Detect if JavaScript is enabled (HTML code)

Send Us a Sign! (Contact Us!)
Word PDF Epub Text

Because of the emergence of Ajax, people don’t disable JavaScript much nowadays.
I don’t know the percentage of people having disabled JavaScript. It is likely under 5%. But if you have a website visited by millions of visitors every month, even 1% is matter!

This is why I wrote the following code:

<noscript>JavaScript is DISABLED.</noscript>

<span id="displayIfJavaScript" style="display:none">JavaScript is ENABLED.</span>
document.getElementById('displayIfJavaScript').style.display = "block";

The text under the noscript tag will be displayed if JavaScript is disabled or not supported. The text under the span tag is not displayed by default and will be showed using JavaScript, this is why we can be sure JavaScript is enabled in that case.


You can obviously change the content of the noscript and span tags. You could, for example, hide a form which uses JavaScript validation to non-JavaScript users by putting the HTML code of the form under the span tag.

Please see below the above script in action:

JavaScript is DISABLED.




1 thought on “Detect if JavaScript is enabled (HTML code)”

Comments are closed.