|
Posted by NC on 10/11/30 11:59
Jim wrote:
>
> How do I check if javascript is enabled in PHP?
The temptation is to use get_browser() function, but it must be
resisted. get_browser() provides you with information about
what the browser CAN do. It cannot, however, tell you whether
the browser IS ALLOWED to do all it can. For example, many
browsers are capable of supporting JavaScript, but in many,
its support can be disabled.
So it's tricky. You can't do "it in one sitting"; you need to
output something (including some JavaScript), then see how the
client reacts to it. For example, this could be your index.php:
<html>
<head>
<script language="JavaScript">
window.location =
'http://www.yoursite.com/index1.php?js=1&token=<?php
echo time();
?>';
</script>
</head>
<body>
<p>Sorry, your browser does not support JavaScript...</p>
</body>
</html>
In index1.php, you check if $_GET['js'] is indeed 1 and if
$_GET['token'] is reasonably close to server's current time.
You will also need a mechanism to propagate this piece of
information...
Cheers,
NC
Navigation:
[Reply to this message]
|