10 December 2010

How to check whether javascript is enabled or not on client browser

This is a very common problem faced by web developers, when they want to develop a registration form for a website, which in turn depends on JavaScript for form validation or may be some other purpose, and then in that case, you may want to detect the settings of client’s browser and redirect him to different page and ask him to enable JavaScript.

Today I will explain you How to check this setting and redirect to a different page accordingly ?
We can detect whether user has enabled javascript or not in his browser by using noscript tag and if the JavaScript is disabled then the code within this noscript tag will be executed.

It is a two step process

1:- First add this code to your home page ,if javascript is enabled then it will redirect you to another page ie hello1.htm

<meta http-equiv="refresh" content="2; URL=hello1.htm">

2:- Create another file say "hello1.htm" ,where you will show message

“It seems that your browser that doesn't support JavaScript. Please enable it if you want to use our services” or whatever message you want to print

So process is very simple and easy