Latest Entries »

Wednesday, May 5, 2010

How to detact javascript is enable or not in the client browser

There are various kind of solution to check the javascript support of client browser. In here I'll provide a solution to block client access who have not enabled javascript in his/her browser.

In this example I user index.html which clients want to visit. And user enable_js.html which will redirect clients from index.html page when their browser not support to javascript.


<noscript>
<meta equiv="refresh" content="0;URL=enable_js.html">
</noscript>


Add above code into the body (between body tags) of index.html. This part will redirect clients who user browsers which not support for javascript to enable_js.html. If javascript is enable, then nothing happent from this code.



<h2 id="nojs" style="font-family: Verdana,Arial,Helvetica,sans-serif; color: rgb(204, 0, 0);">
JavaScript is turned off in your web browser. Turn it ON (Enable) to access the website, then refresh the page.
</h2>
<script>
document.getElementById("nojs").style.display="none";
alert("Javascript enabled successfully! Press ok to continue");
window.location = "index.html";
</script>


Add above code into the body of enable_js.html. This will display error massage when javascript is disable in client's browser. After enable javascript and refresh this page will provide alert with informing the javascript is successfully working. And after press ok it will redirect to the index.html.

0 comments: