Detect Web Browser Enable or Disable JavaScript – JavaScript Example

By | June 20, 2019

In article Disable JavaScript with Android Chrome Browser we recommend google chrome to disable site javascript. You may wonder how to implement this functionality by programming.

In this tutorial, we will write an example to help you do it.

Before we start to program, we should know a key method:

<noscript> tag will displayed when javascript disabled.

So we can write this example based on <noscript>.

Here is an example code.

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Detect Web Browser Enable or Disable JavaScript</title>
<style type="text/css">
#jsbox{display:none;}
</style>
</head>
<body>
<div id="jsbox"><pre style="font-family: Courier new; text-align: center; border: 1px solid red;"><strong>Javascript</strong> is <span style='color: red'>enabled</span> in your web browser.</pre></div>
<noscript>
    <pre style="font-family: Courier new; text-align: center; border: 1px solid red;"><strong>Javascript</strong> is <span style='color: red'>disabled</span> in your web browser.</pre>
</noscript>
<script type="text/javascript" >
function detect(id){
var obj = document.getElementById(id);
obj.style.display = 'block';

}
detect('jsbox');
</script>
</body>
</html>

When javascript is enable.

javascript is enable

When javascript is disabled.

javascript is disabled

Leave a Reply

Your email address will not be published. Required fields are marked *