Klaus Hartl schrieb:
Dan G. Switzer, II schrieb:
<meta http-equiv="refresh" content="2;url=page.htm?js=false">
<script type="text/javascript">
self.location = "page.htm?js=true";
</script>
In this example if JS is enabled, the JS code would be executed
redirecting
the user to page w/a URL parameter indicating that JS was enabled. If
the JS
code doesn't execute, then the meta refresh would take over.
However, I can't emphasis this enough, testing for JS is really
unnecessary
for all the work you've been talking about. You keep saying you want
to make
your code easier to manage and develop and detecting for JS in this
case is
just adding more complexity.
It's much easier to just write the JS and if it doesn't execute then
let the
server-side code re-enforce the behavior.
The last time I wrote any kind of detection script, was for a project
that
required Flash. It's been 9 years since I've written a script to
detect for
JS--and that was because I didn't know better.
I second Dan. And the example above is one of the most annoying things
you can do to a user: breaking the back button.
PS: And even that method isn't fool-proof. You can always simply
deactivate JS with two clicks when you're already on the page in question...