Ben
Ben

Reputation: 57209

Javascript toggle enabled/disabled

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

Answers (5)

Quentin
Quentin

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

Dai
Dai

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

MatTheCat
MatTheCat

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

user479870
user479870

Reputation:

<script></script>
<noscript>Please enable Javascript.</noscript>

http://www.w3.org/TR/REC-html40/interact/scripts.html#h-18.3.1

Upvotes: 3

Adam Hopkinson
Adam Hopkinson

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

Related Questions