It's been tried many times, but this actually works.
Three part code. The first is the "<noscript>" tag. This is virtually worthless. The NoScript plugin explicitly ignores this unless it is following a blocked script by default. Other options can be set to ignore it more often, but typically it won't do anything by itself unless scripts are blocked by the browser and NOT NoScript. So I'd include it anyway.
One of the following two setups will probably suit your needs:
<noscript>You have Javascript disabled via normal methods.</noscript>
<noscript><meta http-equiv=refresh content=1;URL=nojspage.htm></noscript>
The second version above... if someone has installed NoScript, it is likely they are also blocking meta redirects within <noscript> tags anyway (this is a plugin option).
The second part is to import your Javascript file into the page. You can use the standard method for doing this... keeping your javascript file in the head of the page... write out the script inline... use my nifty trick (explained in the previous post) for importing it in an image file... whatever. Within your javascript, include the following:
var jstracker = document.getElementById('noscript');
jstracker.id = "script";
jstracker.innerHTML = "Javascript is enabled";
The above will locate on your page a span or div or whatever empty placeholder you decide to use and change its id. I recommend a span. You can leave off the innerHTML portion. Only include this portion of code on the pages you are wanting to test to avoid the error "jstracker has no properties".
And now onto the third part. Within the document you're wanting to test and the above javascript has been included on, add one of the following:
<img src="zeropximage.gif" onload="donoscript=function(){if(document.getElementById('noscript')){nsspan=document.getElementById('noscript');nsspan.innerHTML='you are blocking scripts with NoScript';}};setTimeout(donoscript,3000);">
<span id="noscript"></span>
<img src="zeropximage.gif" onload="donoscript=function(){if(document.getElementById('noscript')){document.write('<meta http-equiv=refresh content=1;URL=noscriptpage.htm>}};setTimeout(donoscript,3000);">
<span id="noscript"></span>
Just a warning: the second setup... using a document.write... will likely break the page. You could attempt to find the head element and appendChild the meta tag after creating and modifying it with DOM but it the refresh will not be performed even though you will be able to view the fruits of your labor in the source code. That being said: you could create a new element elsewhere on the page using this method so long as it isn't an action of any kind: plain text or general html... an image... whatever.... all ok.
The delay is on purpose. Depending on the length of your script and the page you could make the delay shorter. You want to give your script enough time to load and change the id of that span before your browser has a chance to check for the old id.
Again, document.write will likely break the page. You can pretty much expect to have a white page that never loads, or an "Operation Aborted" error (IE). If you're wanting to force users to enable Javascript to use the page, this would be a pretty effective method, but it is not at all friendly. If you want to kindly say something else... you might try an alert('please disable NoScript'); or something like that.
This works because the browser is still able to handle Javascript. It's for that same reason that whatever you put within a <noscript> tag will be ignored. If the browser/visiting user is going to lie to me about being able to view javascript, then I'll simply lie back by not admitting that the script I'm running is a script.
I used this method on a journal site that doesn't "allow" javascript to foul up NoScript users. The desired result being so that I could test the ip address and username of the visitor against a list of those I'd rather not have viewing my posts. Kind of needed php and javascript for that... so I break the page using the above document.write if they don't have js enabled.
On a side note: unless you're browsing from a text reader (the likes of which I've never known to actually be in anyone's possession), the user can view and handle Javascript. If they can't: THEY'RE LYING. I'm sorry but no one has a browser that old anymore. You'd have to be on a version of windows pre-3.1. If you're on a machine THAT old... well you deserve what you get, but congratulations on keeping your hard drive alive that long. The average hard drive only lasts 4 years. Even my cell-phone handles javascript ffs. So I don't want to hear about this 15% of users that "can't" view Javascript... OH YES THEY CAN!! They simply have it disabled or are running NoScript or something of the like. Now that you know this, you can go forward with making pages that are nice to these people, or you can be mean and kick them off your page until they grow up and allow it.