On Thu, 2011-04-28 at 10:17 -0400, tedd wrote: > 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> > > </form> > > <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, > > > >-- > >Geoff > > Geoff: > > 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: > > http://www.webbytedd.com/b1/ajax-js-dection/ > > Or do it unobtrusively as I have shown before. > > Cheers, > > tedd > > > -- > ------- > http://sperling.com/ > I'm not sure if my earlier reply got through, but here it is again (or at least the general gist of it) There are ways you can detect if a browser is *capable* of running Javascript using $_SERVER['HTTP_USER_AGENT'] and an up-to-date browscap.ini file. This will allow you to check if the browser indicated by the user agent. However, there are caveats to this approach: * A browser might be sending the wrong user agent string, there are plenty of plugins which do this * A browser might be capable of running Javascript but might have it turned off or otherwise blocked * Filtering may be going on by a proxy server or firewall that strips out Javascript (sounds stupid but happens in paranoid businesses) Like everyone has mentioned thus far, it's better to use progressive enhancement or try to avoid relying on Javascript at all. Even a website as complex as Facebook allows users to go on it without needing a browser that runs Javascript. Something as complex as Google Docs has a very clear need for Javascript though, so you wouldn't expect that to work without it. Lastly, if you're creating the website for a government or business, you really need to make it work without Javascript, as a lot of countries make it illegal to discriminate against a disability, which you would be doing if you made a site that was unusable without Javascript. After all, there are many speech and Braille browsers out there that can't take advantage of Javascript, and a lot of Javascript apps which require mouse interaction to run (mouseover/hover events, etc) -- Thanks, Ash http://www.ashleysheridan.co.uk