JavaScript has always been popular but with the boom in Ajax web development it has given JavaScript a new meaning. Most of the websites today relies heavily on JavaScript. This means you need to make sure that if your users can support JavaScript. In this article we are going to tackle the problem of finding out if the JavaScript is enabled on the user’s browser or not.

Introduction:

JavaScript has always been popular but with the boom in Ajax web development it has given JavaScript a new meaning. Most of the websites today relies heavily on JavaScript. This means you need to make sure that if your users can support JavaScript. In this article we are going to tackle the problem of finding out if the JavaScript is enabled on the user’s browser or not.

What about Request.Browser.JavaScript? 

You might use the result of the Request.Browser.JavaScript property and determine if the JavaScript is enabled on the browser or not. Unfortunately, Request.Browser.JavaScript simply returns if the browser is capable of handling JavaScript. So, this means that even if you disable the JavaScript in the browser this property will still return true since JavaScript can be handled by the browser. Let’s see a different way to solve this problem.  

The part of the idea discussed here was proposed by Paul Weston (http://forums.asp.net/t/1164454.aspx). Create two divs just like shown below:

 <div id="jsEnabled" style="visibility:hidden">

JavaScript is enabled

</div>

<div id="jsDisabled">

JavaScript is disabled

</div>

 The first div contains the text "JavaScript is enabled" while the second one says "JavaScript is disabled". The first div is also made hidden. Now, we attach the checkJavaScriptValidity function to the onload event of the page.

 <body onload="checkJavaScriptValidity()">

 checkJavaScriptValidity hides the second div and make the first one active. If JavaScript is enabled you will see the first div which says "JavaScript is enabled". If JavaScript is disabled you will see the second div which says "JavaScript is disabled".  

<script language="javascript" type="text/javascript">

function checkJavaScriptValidity()

{

document.getElementById("jsEnabled").style.visibility = 'visible';

document.getElementById("jsDisabled").style.visibility = 'hidden';

}

</script>

Conclusion:

In this article we learned how to find out if the JavaScript is enabled on the user’s browser. A good idea will be to use this script in a separate page which tests different aspects of the user’s browser. 

I hope you liked this article, happy coding!