-4

Is there a JavaScript function to tell me if JavaScript is turned on or not? something like this one:

<script>
    if (true) {
        document.write("JavaScript is turned on!");
    }
</script>
Marty
  • 39,033
  • 19
  • 93
  • 162
Maizere Pathak
  • 303
  • 1
  • 9
  • 7
    How are you envisioning the ability to check whether JavaScript is enabled *using JavaScript*? – Marty Feb 06 '13 at 04:49
  • http://stackoverflow.com/questions/6683594/check-whether-javascript-is-enabled/6683647#6683647 explains how to use ` – Mike Samuel Feb 06 '13 at 04:50
  • 2
    [Bulletproof JavaScript Detection](http://thedailywtf.com/Articles/Bulletproof-JavaScript-Detection.aspx) – R. Martinho Fernandes Feb 08 '13 at 12:49

2 Answers2

1

If it is enabled, the code runs. If it is not enabled the code does not run. There is nothing that is sent to the server that tells you if it is enabled.

Have you looked at the noscript element?

epascarello
  • 204,599
  • 20
  • 195
  • 236
0

You should just use the noscript tag

<noscript>
Enable javascript man! 
<noscript>

Or:

<script>
document.write("Hello World!")
</script>
<noscript>Your browser does not support JavaScript!</noscript>
Randall Hunt
  • 12,132
  • 6
  • 32
  • 42
  • 7
    http://w3fools.com/ – Mike Samuel Feb 06 '13 at 04:48
  • 3
    Why use crap like w3schools, when the [HTML spec](http://www.w3.org/TR/html-markup/noscript.html) and [mozdev](https://developer.mozilla.org/en-US/docs/HTML/Element/noscript) are readily available. – Mike Samuel Feb 06 '13 at 04:53
  • Because if you use google w3schools is the first result. Also the spec is incomprehensible to the average noob. Mozdev is good but is somewhat limited in scope. – Randall Hunt Feb 06 '13 at 04:54
  • Do you prefer frequently wrong & always scummy to incomprehensible or limited in scope? – Mike Samuel Feb 06 '13 at 04:57
  • If it works, yeah. Do you have common+recent(2010+) examples of things that have been wrong (genuine question)? I just see so much w3schools hate but I'm not sure it's warranted. – Randall Hunt Feb 06 '13 at 05:03
  • 1
    Fair enough. I looked through w3fools to see if there are still obvious errors and I didn't have to go far, and their take on http://www.w3schools.com/html/html_elements.asp is still valid. It looks like w3fools has kept up-to-date. – Mike Samuel Feb 06 '13 at 05:08