At 9:02 AM +0100 4/28/11, Geoff Lane wrote:

FWIW, it's possible to detect whether or not Javascript is available,
but not AFAICT at 'first contact' because you need the 'first contact'
page to do something to prove that JS is available, from which you can
assume that JS is not should that something not be done. For example,
you can make the link to a page into a form submission - e.g:

  <form name='jstest' action='myscript.php' method='post'>
  <input type='hidden' name='wehavejs' value=1>
<a href='myscript.php' onClick="document.forms['jstest'].submit();return(false);">
  Click Here</a>

The form is submitted if the browser has JS and so the hidden input
field is posted. However, if the browser doesn't have JS the default
behaviour occurs when the link is clicked and so the field is not
posted. Hence we can use isset($_POST['wehavejs']) to determine
whether or not the browser has JS capability.

Thanks again,



You are correct about "first contact" -- you need to launch the browser to check to see if the browser has javascript enabled. There's currently no way for the server to see what the user has selected for their browser before the browser launches.

It is true that the $_SERVER global provides all sorts of information about the requester and I suppose it could also contain the browser's javascript configuration, but it doesn't.

However, JavaScript detection doesn't require a user's response, as you have proposed via a form.

Instead, you can simply add an "onload()" operation to the page and detect javascript, such as:

Or do it unobtrusively as I have shown before.




PHP General Mailing List (
To unsubscribe, visit:

Reply via email to