• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checking browser version & JavaScript enabled

 
Krish Pat
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you everyone for the insight on how to approach this. I am going to try out the suggestions right away................
Krish
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic