About This Product
FontsMadeEasy.com
 
Search This Database:
| Over 5000 Free Fonts | Tutorials | Javascript Forum | Other Javascript Resources | Cheat Sheet
Tutorial archive
General Questions
Javascript 1.2
Navigation
Numbers
Strings
Object Model
Reference Manual
Dialog
Windows
Frames
Forms
Images
Mouse Events
Colors
File Access
Control Status Bar
Dates and Time
Cookies
Client Information
Bookmarklets


Browser Version

Question: How do I detect the browser version?

Answer: In most cases, you can use the value parseInt(navigator.appVersion). In JavaScript-aware browsers, this value is the number of compatible Netscape Navigator version. (Note that in Microsoft Internet Explorer 3 the string navigator.appVersion begins with 2, which is intended to reflect the compatibility with Netscape Navigator 2.)

In some cases, however, you might need the full version number in the major.minor format. In Netscape Navigator, you can use parseFloat(navigator.appVersion). In Internet Explorer, the full version number is contained in the string navigator.appVersion (or navigator.userAgent) after "MSIE". The full version number of Opera is contained in the string navigator.userAgent after "Opera".

Thus, to get the full version number of any of the above browsers, you can use the following code:

var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;

var fullVersion = parseFloat(nVer);
var majorVersion = parseInt(nVer);

// In Internet Explorer, the true version is after "MSIE" 

if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
 fullVersion = parseFloat(nAgt.substring(verOffset+5,nAgt.length));
 majorVersion = parseInt(''+fullVersion);
}

// In Opera, the true version is after "Opera"

if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
 fullVersion = parseFloat(nAgt.substring(verOffset+6,nAgt.length));
 majorVersion = parseInt(''+fullVersion);
}

document.write('Full version = '+fullVersion+'<br>');
document.write('Major version = '+majorVersion);
In your browser, this code produces the following output:

BackBack