One thing to point out about mine and Dan's suggestion is that your Seach
engine ranking will take a hit if you use this method. Google penalizes
sites who use redirects to other pages.

Depending on why you need to check for JS, you might consider using this
method only for portions of the site which will not receive search engine
hits. Such as admin areas, online forms, etc. 

-----Original Message-----
From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Dan G. Switzer, II
Sent: Friday, April 20, 2007 8:16 AM
To: jquery-en@googlegroups.com
Subject: [jQuery] Re: Best way to determine if a user has Javascript
enabled?


Rick,

>Good morning, all...
>
>Is there a fool-proof way to determine if a user has Javascript enabled 
>in their browser?

As discussed on another mailing list, there's no real need to detect if JS
is enabled. If you write unobtrusive JavaScript (which is what jQuery helps
you to do) if the user has JS disabled, things will continue to work.

There's no reason to have separate JS/non-JS pages in most cases--especially
for the kind of things you're working on.

That said, the most full proof way I'm aware of to test if JS is
enabled/disabled is driving traffic through a splash page which does a
redirect.

<meta http-equiv="refresh" content="2;url=page.htm?js=false">

<script type="text/javascript">
self.location = "page.htm?js=true";
</script>

In this example if JS is enabled, the JS code would be executed redirecting
the user to page w/a URL parameter indicating that JS was enabled. If the JS
code doesn't execute, then the meta refresh would take over.

However, I can't emphasis this enough, testing for JS is really unnecessary
for all the work you've been talking about. You keep saying you want to make
your code easier to manage and develop and detecting for JS in this case is
just adding more complexity. 

It's much easier to just write the JS and if it doesn't execute then let the
server-side code re-enforce the behavior.

The last time I wrote any kind of detection script, was for a project that
required Flash. It's been 9 years since I've written a script to detect for
JS--and that was because I didn't know better.

-Dan


Reply via email to