| Author |
Checking browser version & JavaScript enabled
|
Krish Pat
Ranch Hand
Joined: Jul 31, 2002
Posts: 32
|
|
Greetings to everyone, How do I check for the browser version(IE or Netscape) on the client machine and also check if JavaScript is enabled using JavaScript? If JavaScript is disabled or an older version of a browser is used, I don't want to allow the client to enter into my application which is in Java/JSP. Thanks a gazillion in advance,
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56185
|
|
You can grab the "user-agent" request header in order to sniff the browser and version. But keep in mind that this is not fool-proof since the header can be spoofed. Also parsing this header is not deterministic since there is no "standard" format for what is returned. If you are just checking for a few major browsers, then you can check the headers they return and code some specific checks. But a general solution is difficult. (For example, if someone using a 3Com Audrey hits your page, it will report that it is Netscape 4 running on Windows 98!) You can't check if JavaScript is enabled using JavaScript because if it isn't enabled, you can't run ANY. There are some tricks you can use though, that have been discussed in these forums. Do a search and you are liable to find a few. hth, bear
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56185
|
|
P.S. Here's a list of some known user-agent strings. Be afraid, be very afraid! hth, bear [ March 04, 2003: Message edited by: Bear Bibeault ]
|
 |
sunitha reghu
Ranch Hand
Joined: Dec 12, 2002
Posts: 937
|
|
Another option is using a <noscript> tag if the javascript is enabled direct the user to one link if not tell the user to click the link which doesnt use js <Script language="JavaScript"> document.write(" ");//check for js enabled </Script> <NoScript> JavaScript is disabled. pls use this link (www.watever.com)to access my homepage </NoScript>
|
 |
sampy jagan
Ranch Hand
Joined: Sep 17, 2002
Posts: 34
|
|
To determine if a user has JavaScript enabled, the <noscript> tag suggested by Sunita seems to be a good option. Alternatively you can create a HIDDEN form field in the HTML and call a JavaScript function on the onload event, altering the value of this HIDDEN form field. That way, if the form field has been altered, then we know JavaScript is enabled (else the JavaScript function that alters the HIDDEN form field wouldn't have been called). Here is the sample code for Checking Borwser Name & Ver. call the above functions on the body onload event� Regards Jagan
|
 |
Krish Pat
Ranch Hand
Joined: Jul 31, 2002
Posts: 32
|
|
Thank you everyone for the insight on how to approach this. I am going to try out the suggestions right away................ Krish
|
 |
 |
|
|
subject: Checking browser version & JavaScript enabled
|
|
|