Page 1 of 1

Detecting Javascript

Posted: Thu Dec 27, 2007 9:20 am
by onion2k
What's a good method for detecting whether or not Javascript is switched on? I can think of a couple of methods (like putting <noscript><input type="hidden" name="noscript" value="1"></noscript>" in a form) but I was wondering what other options there are. Sending the user to a page that detects javascript and then uses a meta refresh to forward the user to a different page seems to be the 'recommended' approach. It seems pretty nasty to me though..

I know the best method is to write the site in a way that makes it unnecessary and then use JS to extend it .. but I'm working on a site that requires it.

Posted: Thu Dec 27, 2007 9:37 am
by VladSun
You could use a reverse approach :)

In no_js_enabled.html

Code: Select all

window.top.location.replace("/with_js_enabled.html")
But I can't advice you what would be best ...

Posted: Thu Dec 27, 2007 3:40 pm
by onion2k
I've decided to use a lazy, nasty hack .. putting a meta refresh tag inside a <noscript> block. If the user doesn't have scripting enabled they're shuffled off to the 'you got no Javascript' page. It's horrid but it works.

Posted: Thu Dec 27, 2007 4:20 pm
by alex.barylski
I use:

<noscript>
<ing src="check.php" />
</noscript>

Inside my login forms...from that point on I just keep the value in a session...

Posted: Thu Dec 27, 2007 6:25 pm
by Ambush Commander
onion2k: I've seen that method being used before. I find it very, very annoying, but that's just the fact that the site needs JS speaking :-).

If you don't want to use a bouncer page, it might be a good idea to make pages "disabled" by default, and then have JavaScript enable them. This incurs, however, a performance penalty if you have many pages.

Posted: Thu Dec 27, 2007 8:43 pm
by Kieran Huggins
As an added reason not to require javascript, spiders won't index your site properly.

Posted: Fri Dec 28, 2007 3:01 am
by onion2k
I don't care about spidering. This is for something that won't be available to the public anyway. I just don't want the users moaning that my code doesn't work so I'm looking at ways to detect potential problems.

Posted: Fri Dec 28, 2007 4:31 am
by VladSun
I would use the Mozilla Prism browser for web applications. This eliminates many of the problems which I have with JS compatibility, browser specific issues, etc. Also, it eliminates the Back/Refresh problem with AJAX applications - these functions simply don't exist in this browser (i.e. as buttons) :)

Posted: Fri Dec 28, 2007 10:36 am
by Kieran Huggins
While I agree with the spirit of the previous suggestion, I'd go with XULrunner

Posted: Sat Dec 29, 2007 6:29 am
by JAB Creations
I run a counter cookie at my site (used to trigger secrets on the last version and some of the retained secrets and the ones I have to add back...when they hit a certain number).

You could simply use the noscript element with an image though only have that noscript element present when the visitor's counter cookie equals a low value such as 2. Besides those who do not support cookies (bunker building apologetical privacy advocates) you'd get a unique and highly accurate idea of how many people have JavaScript disabled by the number of times the image was loaded in your access log for the month. This could be skewered by those who reset their cookie though in general unless you setup some sophisticated serverside IP tracker that reads your log and itself serves the image (since PHP is nifty and can do so) this makes the most sense to me.

I know AWStats tracks this by leaving the data in a requested URL that it later reads when compiling the log for you though I'm not exactly sure how it does it nor have I figured out how to have it show me those particular stats.