Eventually I would want to redirect them to content that is able to work in the absence of JS, but I need this detection as a placeholder to start.
<noscript> element for an unexplained reason.
I’d like to add my .02 here. It’s not 100% bulletproof, but I think it’s good enough.
So, what you really want is a “redirection” to a page that says “turn on JS, silly”. But, of course, you can’t reliably do meta redirections. So, here’s the suggestion:
…where all of the content in your site is wrapped with a div of class “pagecontainer”. The CSS inside the noscript tag will then hide all of your page content, and instead display whatever “no JS” message you want to show. This is actually what Gmail appears to do…and if it’s good enough for Google, it’s good enough for my little site.
Users without js will get the
next_page link – you can add parameters here so that you know on the next page whether they’ve come via a JS/non-JS link, or attempt to set a cookie via JS, the absence of which implies JS is disabled. Both of these examples are fairly trivial and open to manipulation, but you get the idea.
then check your access logs to see how many times this image has been hit. A slightly crude solution, but it’ll give you a good idea percentage-wise for your user base.
The above approach (image tracking) won’t work well for text-only browsers or those that don’t support js at all, so if your userbase swings primarily towards that area, this mightn’t be the best approach.
<noscript><meta http-equiv="refresh" content="0; url=whatyouwant.html" /></noscript>
<form onsubmit="this.js_enabled.value=1;return true;"> <input type="hidden" name="js_enabled" value="0"> <input type="submit" value="go"> </form>
This will change the value of js_enabled to 1 before submitting the form. If your server-side script gets a 0, no JS. If it gets a 1, JS!