Javascript Reference
Categories: navigator

javascript navigator userAgent

@March 15, 2008, 1:22 a.m.
userAgentFirefox/Netscape/NN 2 IE 3 Chrome/Safari/DOM n/a  

Read-only  

Provides information about the browser software, including version, operating system platform, and brand. This is the most complete set of information about the browser, whereas appVersion and appName properties provide subset (and not always correct) data. Typical data for the userAgent property looks like the following examples from IE and Navigator:

Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Q312461)
Mozilla/5.0 (Macintosh; U; PPC; en-US; rv:0.9.4) Gecko/20011022 Netscape6/6.2
 

Do not rely on the length or position of any part of this data, as it may vary with the browser, version, and proxy server used at the client end. Instead, use the indexOf( ) method to check for the presence of a desired string. To extract only the actual application version number for IE, use the following function:

function readIEVersion( ) {
    var ua = navigator.userAgent;
    var IEOffset = ua.indexOf("MSIE ");
    return parseFloat(ua.substring(IEOffset + 5, ua.indexOf(";", IEOffset)));
}
 
Example
 
if (navigator.userAgent.indexOf("MSIE") != -1) {
    var isIE = true;
}
 
Value

String.

 
Default

Browser dependent.


Powered by Linode.