Detecting Javascript
Moderator: General Moderators
Detecting Javascript
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.
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.
You could use a reverse approach 
In no_js_enabled.html
But I can't advice you what would be best ...
In no_js_enabled.html
Code: Select all
window.top.location.replace("/with_js_enabled.html")
There are 10 types of people in this world, those who understand binary and those who don't
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
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.
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.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
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) 
There are 10 types of people in this world, those who understand binary and those who don't
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
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.
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.