I don't want to deal with users who have javascript turned off, so I want to just prevent them from using my application. I want to detect if the user has javascript turned on so I can redirect them to a page that tells them they need to use javascript. I'm sure its in the request header. Anyone have any ideas how I can do this?
Do you really need a redirect at all? Put the message in a <noscript>
element, and it will only be displayed to those it applies to.
You only need html:
<noscript><meta http-equiv="refresh" content="0;url=http://example.com/use_js.html" /></noscript>
This of course won't prevent the server from serving content, it only will output this meta refresh
tag, which will be parsed (and executed by redirecting the user) by clients that got no javascript or javascript disabled.
The noscript
tag is the easiest solution, though not exactly whay you're looking for.
<noscript>Get outta here.</noscript>
You can't. The server has no idea what the client has enabled. You can't even "detect" if Javascript is disabled from the client (because what would you use to do so?).
You can use tricks to show content when Javascript is disabled (for instance, a <noscript>
tag, or using Javascript to hide content that is meant for JS-only).
There is no way to detect JavaScript on the server side. However, you can use a NOSCRIPT
tag to display a message indicating that your website requires JavaScript.
For an example, turn JavaScript off in your browser and load a Stack Overflow page. There'll be an obnoxious red message across the top of the page warning you that the site works best with JavaScript enabled. You can examine the Stack Overflow source code and CSS styling to see how they implemented it.
If you really want to deter non-JavaScript users from using your website, you could put your message in a div
inside the noscript
tag and expand the div
to cover everything on the page.