aspose file tools
The moose likes HTML, CSS and JavaScript and the fly likes Browser detect and IE Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Browser detect and IE" Watch "Browser detect and IE" New topic
Author

Browser detect and IE

elizabeth thomas
Greenhorn

Joined: May 12, 2003
Posts: 7
Hi,
I am using the following simple code to detect the browser version. When I run the code in IE 6.0, I am getting the browser version as "4". Can anyone explains me what the robelm is??
browser_version= parseFloat(navigator.appVersion);
browser_type = navigator.appName;
if (browser_type == "Microsoft Internet Explorer" && (browser_version >= 4)) {
alert ("You appear to be using Microsoft Internet Explorer: " + browser_version);
}
else if (browser_type == "Netscape" && (browser_version >= 4)) {
alert ("You appear to be using Netscape: " + browser_version);
}
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50674

Yes, that is what it does. If you take a look at the value of the navigator.userAgent attribute you will see why it does what it does (but that doesn't mean it actually makes sense).
You will note however, that the correct browser version number is embedded in the userAgent string. This is what you should be using to perform browser determination.
You can use regular expression processing to parse the version number out of the userAgent string.
hth,
bear
[ May 14, 2003: Message edited by: Bear Bibeault ]

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
elizabeth thomas
Greenhorn

Joined: May 12, 2003
Posts: 7
Thank You bear. It worked
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2559

Actually, in most cases a better idea is to detect property supported (such as getElementById) by the browser rather than to detect a browser name. Few brosers like Opera can fake a user agent string.
- Manish
 
IntelliJ Java IDE
 
subject: Browser detect and IE
 
Threads others viewed
Client browser type and platform detection thru Servlets
Problem related to browsers and javascript
IE and NN Compability
Microsoft Longhorn
Navigation Objec tion??Major doubt in it??
MyEclipse, The Clear Choice

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture