Reputation: 57209
What's the best way to toggle a "Please have Javascript enabled" warning?
Currently I've got something like this:
<div id='JSwarning'>ONLY SQUARES DON'T USE JAVASCRIPT</div>
to which I then apply .style.display = "none"
.
This shows the warning on every page for a little while until it loads. There must be a more graceful way. Can I do it with PHP?
(BTW, get_browser()
is not the solution I'm looking for.)
//EDIT
Thanks everyone, that does the trick. Incidentally, to get the page to validate (XHTML 1.0 Strict), I needed to place the child node(s) in a block container.
Upvotes: 3
Views: 599
Reputation: 943220
The best way is to … not. Build on things that work.
JavaScript support is not a binary state. People can turn it on. People can turn it off. JS files can fail to load (because a server is down, or blocked). JS can be selectively enabled (e.g. with the Firefox NoScript extension).
Better to use progressive enhancement.
Upvotes: 0
Reputation: 1510
use the noscript tag
<script language="javascript">
document.write("Hello World!");
</script>
<noscript>
You need to enable javascript to view this page!
</noscript>
Upvotes: 2
Reputation: 18721
Does you apply this rule when DomContentLoaded is fired?
There is <noscript>
too but it seems to me chrome ignores it.
Upvotes: 1
Reputation:
<script></script>
<noscript>Please enable Javascript.</noscript>
http://www.w3.org/TR/REC-html40/interact/scripts.html#h-18.3.1
Upvotes: 3
Reputation: 28795
I think you're after the noscript
tag:
<noscript>ONLY SQUARES DON'T USE JAVASCRIPT</noscript>
It's a browser convention, so you don't need to hide it when js is disabled (the browser does this automatically).
Upvotes: 2