[Javascript] Javascript detection
tedd
tedd at sperling.com
Mon Jan 1 23:11:38 CST 2007
At 1:37 AM +0000 1/2/07, David Dorward wrote:
>On Mon, Jan 01, 2007 at 08:31:09PM -0500, Matt Warden wrote:
>> On 1/1/07, David Dorward <david at dorward.me.uk> wrote:
>> >So - how is it useful to know if the client supports JavaScript or
>> >not? The page works either way.
>>
>> Perhaps we can skip the interview and just help answer the OP's question.
>
>Perhaps if the OP explains his thinking then:
>
>(a) We can learn something
>
>or
>
>(b) We can suggest a better solution
>
>This is a *discussion* list isn't it?
>
>--
>David Dorward http://dorward.me.uk
David et al:
To explain what I'm trying to do is probably too complicated for my
limited communication skills.
The original post that started me on this investigation was simply
"How does one take the value of a javascript variable and carry it
forward to the next page?" However, no one was able to provide an
answer, other than using cookies and I don't want to do that.
However, I believe that it can be done otherwise and that's what I am
trying to accomplish.
What I am doing is not essential to the operation of my web page and
if javascript is not enabled, then the enhancement is not realized
nor needed -- thus satisfying "progressive enhancement" requirement.
So, we should not address that topic any further.
My first step in this investigation is to determine if javascript is
enabled in the user's browser -- the following is my methodology.
1. The user is directed to this url: http://sperling.com/js_detect
The "js_detect" is a folder containing [1] (index.php) the default
file, the code is listed below. As you can see, this [1] (index.php):
a) starts a php session [js]; b) loads a javascript named [2]
(is_js.js); c) makes the current index.php page refresh to
"index1.php" after one second; d) and note, the index.php page has no
visible content -- thus, the user doesn't see anything.
2. Now, javascript [2] (is_js.js) simply executes "a.php" script
after an onload event and passes the js variable to "a.php" via a
javascript POST operation -- IF -- javascript is enabled.
3. The [3] (a.php) simply takes a javascript POST and sets a php
session js variable. Actually the else portion of the code is never
executed for this would never be called is javascript wasn't enabled.
I only present it for clarification.
4. The [4] (index1.php) simply displays the php session variable js.
Now, I don't fully understand why I have conflicting reports. Some
people have the identical browser and OS combinations and report that
it both works and doesn't work.
And, I don't understand why browsers running on LINUX and Opera on
Windows machines fool the script. A more complete accounting is here:
http://www.browsercam.com/public.aspx?proj_id=311334
In any event, the technique works for most browsers and OS's.
Thanks for your review and comment.
tedd
--- code follows ---
[1] --- index.php
------------------------------------------------------------------
<?php session_start();
if (!isset($_SESSION['js']))
{
$_SESSION['js'] = 0;
}
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
<title>?</title>
<script type='text/javascript' src="is_js.js"></script>
<meta http-equiv="refresh" content="1;
URL=http://sperling.com/js_detect/index1.php">
</head>
<body>
</body>
</html>
--- end of index.php
--------------------------------------------------------------------
[2]--- is_js.js ----(Thanks to Matt for the idea given a week
ago)---------------
function is_js()
{
(new Image()).src = 'a.php?js=1';
}
window.onload = is_js;
--- end of is_js.js
--------------------------------------------------------------------
[3] --- a.php
-----------------------------------------------------------------------
<?php session_start();
if (isset($_GET['js']))
{
$js = 1;
}
else
{
$js = 0;
}
$_SESSION['js'] = $js;
?>
--- end of a.php
---------------------------------------------------------------------
[4] --- index1.php
------------------------------------------------------------------------
<?php session_start();
if (!isset($_SESSION['js']))
{
$_SESSION['js'] = 0;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"> <html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
<title>Stuff by tedd</title>
<link rel="stylesheet" href="style.css" media="screen">
</head>
<body>
<p>
Javascript has <?php if($js==0){ echo '<b>not</b>'; } ?> been
detected on the client.
</p>
</body>
</html>
--- end of index1.php
---------------------------------------------------------------------
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
More information about the Javascript
mailing list