[Javascript] Javascript detection

Matt Warden mwarden at gmail.com
Mon Jan 1 19:31:09 CST 2007


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.

Tedd, try something like this:

if (!window.location.indexOf('js=1')) window.location = '?js=1';

You'll want to clean it up a bit because the above will remove any
query string variables (could be bad). Another option:

(new Image()).src = 'setsessionvar.php?js=1';

You can also use XMLHttpRequest, but then what you're really detecting
is if XHR is available, which is not the same as whether JavaScript is
available.

-- 
Matt Warden
Cleveland, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.



More information about the Javascript mailing list