[Javascript] Javascript detection
Nick Fitzsimons
nick at nickfitz.co.uk
Tue Jan 2 10:54:22 CST 2007
On 2 Jan 2007, at 05:11:38, tedd wrote:
> My first step in this investigation is to determine if javascript
> is enabled in the user's browser
<snip>
>
> 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.
>
It doesn't work on Safari 2.0.4, OS X 10.4.8.
Surely the easiest way is to just use self.location.href to redirect
to some page; if JS isn't enabled, it won't do anything. So, (with
prior apologies for any syntactical errors in PHP, which isn't my
usual server-side technology):
<html>
<head>
<?php
if (session_not_already_in_progress()) {
print("<script>self.location.href=\"startSession.php\";</script>");
}
?>
</head>
<body>
<h1>Hello world</h1>
</body>
</html>
where startSession.php does whatever it does (including setting
whatever it needs to detect that the session has already begun in the
function "session_not_already_in_progress"), and then just redirects
back to the above; as the session has been started, the redirection
script won't be created by the server on the second time around, but
the server knows that JS must be enabled for "startSession.php" to
have been requested. On JS-disabled clients, "startSession.php" will
never be requested.
HTH,
Nick.
--
Nick Fitzsimons
http://www.nickfitz.co.uk/
More information about the Javascript
mailing list