Skip to content

Is JavaScript enabled | HTML Example code to Check

  • by

How to detect if JavaScript is disabled?

You can use <noscript> and <meta> tag to check JavaScript enabled. The noscript blocks are executed when JavaScript is disabled. It’s typically used to display alternative content that you’ve generated in JavaScript,

<noscript>
  <meta http-equiv=refresh content='0; url=http://your.domain/noscript'>
</noscript>

Note: It’s not give 100% accurate result, There is not a good way to perform server-side JavaScript detection.

Example of Check If JavaScript Is Enabled

Here is worked code: it redirects a visitor if JavaScript is disabled, example in HTML.

<!DOCTYPE html>
<html>
<head>
 <noscript>
    <meta http-equiv="refresh" content="1;url=error.html">
</noscript>

</head>
<body>

</body>
</html>

Output: If JavaScript enabled then it will not redirect error webpage.

If you want a purely statistical idea of how many of your users have JavaScript disabled, you could do something like:

<noscript>
    <img src="no_js.gif" alt="Javascript not enabled" />
</noscript>

Do comment if you are facing any issue or have any suggestions on this tutorial.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading