3

I am building a html page. I was to make a quick 1 line test which, if the user has javascript enabled says "javascript on" otherwise says "javascript off" just to let them know.

How can I do this?

David19801
  • 11,214
  • 25
  • 84
  • 127

2 Answers2

6
<div id="js_onoff">JavaScript off :(</div>
<script>
    document.getElementById("js_onoff").innerHTML = "JavaScript on, yeah! :)";
</script>
Marcel Korpel
  • 21,536
  • 6
  • 60
  • 80
5
<script type="text/javascript">document.write('JavaScript On');</script>
<noscript>JavaScript Off</noscript>

Maybe?

There are going to be a lot of options here.

Brad Christie
  • 100,477
  • 16
  • 156
  • 200
  • `noscript` elements are ignored by browsers with JavaScript enabled, but blocked (e.g., using an extension like NoScript). – Marcel Korpel Jan 25 '11 at 20:26
  • @Marcel: Actually, it appears the (much) earlier releases didn't but they're [pretty consistently](http://noscript.net/changelog) making that part of their debug efforts (since earlier versions of 2.0.x). – Brad Christie Jan 25 '11 at 20:36
  • Looks nice, but there are more alternatives to block JavaScript. I fear we can never rely on those elements, how much I'd like them to behave in a consistent, cross-browser manner. – Marcel Korpel Jan 25 '11 at 20:40
  • I concur, but it'll never happen. And with all the standards there are for the way CSS/Javascript work and render, I wish they'd all agree on default values/behaviors while they're at it. – Brad Christie Jan 25 '11 at 20:48