post your comment   print   send to a friend
Rate:   0% | Views: 450
Question categories:  JavaScript

The Internet Explorer challenge

Detecting IE using the navigator object is challenging because of the “extra” information stored by IE inside both navigator.appVersion and navigator.userAgent.

If we were to use parseFloat to try and extract the browser version, we would get 4.0, instead of 5.5. This is due to the way parseFloat works - it returns the first number it encounters

To retrieve the version number in IE, utilize any combination of string methods that successfully extracts this information. If you're detecting a single IE version (ie: IE 5.5 and NOT IE5.5+), the string method string.indexOf() will work.

//detect IE5.5
if (navigator.appVersion.indexOf("MSIE 5.5")!=-1)
alert("You are using IE5.5!")

However, it is sometimes necessary to determine an entire range of browser versions (IE 5.5 and up, for example). Our suggestion is to invoke the adage "whatever works." Here is our method to detect a version of IE and up:

//Detect IE5.5+
version=0
if (navigator.appVersion.indexOf("MSIE")!=-1){ temp=navigator.appVersion.split("MSIE")
version=parseFloat(temp[1])
}

if (version>=5.5//NON IE browser will return 0
alert("You are using IE5.5+")

In the above, string.split() is first used to divide navigator.appVersion into two parts, using "MSIE" as the separator. As a result, temp[1] contains the code after "MSIE", with the browser version appearing first. Doing a parseFloat() on temp[1] will retrieve the browser version of IE.

Customer Feedback
Rate:   0% | Views: 450 | Please Rate:  
 
If you have other comments or ideas for future technical tips, please type them here:

Email: (optional)

Comments: (optional)

 Webhosting Service | Domain Name Registration    Back to serch results
Browse the Base
Knowledge Base
Web Design
  Do It Yourself
    JavaScript
Messages
 

Blogging at Aplus.Net

Don't forget to check out our blog ! Keep up to date at Aplus.Net.

Private Area
 
Ask
in Private
   
Personal
Folder
 
Related Questions
 
1. Calculating days remaining until Christmas
 
2. Detecting browser type
 
3. Determining browser type using object detection
 
4. JavaScript and Forms
 
5. The Math object
 
Home Browse Search Ask in Private Personal Folder   Help
powered by web hosting 
  Logged as: Guest