Categories:

JavaScript Kit > JavaScript Reference > Here

Navigator Object

Last updated: January 20th, 2015

The Navigator object of JavaScript returns useful information about the visitor's browser and system.

Note: Starting in IE11, many of its Navigator object properties now return values that are similar to Mozilla Firefox's to prevent the browser from being lumped together with older IE versions by developers during browser detection.

Related Tutorials

Properties

Properties Description
appCodeName The code name of the browser.
appName The name of the browser. In Firefox for example the returned value is "Netscape", while in IE10 and below, it's "Microsoft Internet Explorer" as can be expected. Starting in IE11+, however, the returned value of appName is also "Netscape".
appVersion Version information for the browser (ie: 5.0 (Windows)).
cookieEnabled Boolean that indicates whether the browser has cookies enabled.
language Returns the default language of the browser version (ie: en-US). NS and Firefox only.
maxTouchPoints The maximum number of simultaneous touch contacts supported by the device. IE10+ only.
mimeTypes[] An array of all MIME types supported by the client. NS and Firefox only.
onLine A Boolean that returns true if the browser is online, false if not. Note that different browsers have different minimum requirements when deciding if the browser is online, which may not accurately correlate to whether the browser is in fact able to access the web. In other words, you should not solely rely on the onLine property to detect whether the user is online.

Two events, onoffline and ononline, can be used to react to when the user goes offline and online, respectively. They fire on the BODY element of the page and bubble up to the window object. The following uses the onoffline event to detect when the user has gone "offline":

if (window.addEventListener){
 document.body.addEventListener("offline", function(e){alert("User went offline")}, false)
}
else if (window.attachEvent){
 document.body.attachEvent("onoffline", function(e){alert("User went offline")})
}
else{
 document.body.onoffline=function(e){alert("User went offline")}
}

platform[] The platform of the client's computer (ie: Win32).
plugins An array of all plug-ins currently installed on the client. NS and Firefox only.
systemLanguage Returns the default language of the operating system (ie: en-us). IE only.
userAgent String passed by browser as user-agent header. The userAgent value for IE9 is "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1;)" while for Mozilla Firefox 35, it's "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0".

Starting in IE11+, the userAgent return value is a drastic departure from all older versions' of IE. In IE11 Windows 8 the returned string is "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko". This is different from previous versions in the following notable ways:

  • The compatible ("compatible") and browser ("MSIE") keywords have been removed, meaning you can no longer just look for "MSIE" in the userAgent to sniff out IE in IE11 or above browsers.
  • The version of the browser is now reported by a new revision ("rv") keyword.

Revew the example section further below to see how to detect various versions of IE using navigator.userAgent, including in IE11 and above.

You can probe the userAgent property for mobile browsers such as iPhone, iPad, or Android. The following variable returns true if the user is using one of the following mobile browsers:

//returns true if user is using one of the following mobile browsers
var ismobile=navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)|(android)|(webOS)/i)

userLanguage Returns the preferred language setting of the user (ie: en-ca). IE only.

Your browser's navigator Information

Using some of the above properties, lets display some information about your browser, live:

Additional browsers' Navigator Information

Below shows you what the navigator object would return for some of the popular browsers/Operating System combinations out there:

Internet Explorer 11 (Windows 7)

appCodeName: Mozilla
appName: Netscape
appVersion: 5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MDDC; .NET4.0C; .NET4.0E; rv:11.0) like Gecko
userAgent:Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MDDC; .NET4.0C; .NET4.0E; rv:11.0) like Gecko
platform: Win32

Internet Explorer 9.0 (Windows 7)

appCodeName: Mozilla
appName: Microsoft Internet Explorer
appVersion: 5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MDDC; .NET4.0C; .NET4.0E)
userAgent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MDDC; .NET4.0C; .NET4.0E)
platform: Win32

Internet Explorer 8.0 (Windows 7)

appName: Microsoft Internet Explorer
appVersion: 5.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MDDC; .NET4.0C; .NET4.0E)
userAgent: Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MDDC; .NET4.0C; .NET4.0E)
platform: Win32

Internet Explorer 7.0 (Windows XP)

appCodeName: Mozilla
appName: Microsoft Internet Explorer
appVersion: 4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)
userAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)
platform: Win32

Internet Explorer 6.0 (Windows XP)

appCodeName: Mozilla
appName: Microsoft Internet Explorer
appVersion: 4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
userAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
platform: Win32

Internet Explorer 5.5 (Windows XP)

appCodeName: Mozilla
appName: Microsoft Internet Explorer
appVersion: 4.0 (compatible; MSIE 5.5; Windows NT 5.1; .NET CLR 1.1.4322)
userAgent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1; .NET CLR 1.1.4322)
platform: Win32

Internet Explorer 5.23 (Mac Panther 10.3.7)

appCodeName: Mozilla
appName: Microsoft Internet Explorer
appVersion: 4.0 (compatible; MSIE 5.0; Macintosh; I; PPC)
userAgent: Mozilla/4.0 (compatible; MSIE 5.23; Mac_PowerPC)
platform: MacPPC

Firefox 35 (Windows 7)

appCodeName: Mozilla
appName: Netscape
appVersion: 5.0 (Windows)
userAgent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0
platform: Win32

Firefox 5.0 (Windows 7)

appCodeName: Mozilla
appName: Netscape
appVersion: 5.0 (Windows)
userAgent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0
platform: Win32

Firefox 2.0 (Windows XP)

appCodeName: Mozilla
appName: Netscape
appVersion: 5.0 (Windows; en-US)
userAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13
platform: Win32

Firefox 1.0 (Preview Release) (Windows XP)

appCodeName: Mozilla
appName: Netscape
appVersion: 5.0 (Windows; )
userAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20040913 Firefox/0.10
platform: Win32

Firefox 1.04 (Windows XP)

appCodeName: Mozilla
appName: Netscape
appVersion: 5.0 (Windows; en-US)
userAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4
platform: Win32

Firefox 1.0 (Mac Panther 10.3.7)

appCodeName: Mozilla
appName: Netscape
appVersion: 5.0 (Macintosh; en-US)
userAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0 StumbleUpon/1.999
platform: MacPPC

Firefox 1.0 (Linux)

appCodeName: Mozilla
appName: Netscape
appVersion: 5.0 (X11; en-US)
userAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20041111 Firefox/1.0
platform: Linux i686

Chrome 39 (Windows 7)

appCodeName: Mozilla
appName: Netscape
appVersion:5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36
userAgent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36
platform: Win32

Chrome 12 (Windows 7)

appCodeName: Mozilla
appName: Netscape
appVersion: 5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.112 Safari/534.30
userAgent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.112 Safari/534.30
platform: Win32

Opera 25 (Windows 7)

appCodeName: Mozilla
appName: Netscape
appVersion: 5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36 OPR/25.0.1614.50 (Edition Campaign 67)
userAgent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36 OPR/25.0.1614.50 (Edition Campaign 67)
platform: Win32

Opera 11.1 (Windows 7)

appCodeName: Mozilla
appName: Opera
appVersion: 9.80 (Windows NT 6.1; U; en)
userAgent: Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.10
platform: Win32

Opera 9.24 (Identify as Opera, default setting) (Windows XP)

appCodeName: Mozilla
appName: Opera
appVersion: 9.24 (Windows NT 5.1; U; en)
userAgent: Opera/9.24 (Windows NT 5.1; U; en)
platform: Win32

Opera 7.5 (Identify as MSIE 6.0) (Windows XP)

appCodeName: Mozilla
appName: Microsoft Internet Explorer
appVersion: 4.0 (compatible; MSIE 6.0; Windows NT 5.1)
userAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Opera 7.50 [en]
platform: Win32

Opera 7.5 (Identify as Opera) (Windows XP)

appCodeName: Mozilla
appName: Opera
appVersion: 7.50 (Windows NT 5.1; U)
userAgent: Opera/7.50 (Windows NT 5.1; U) [en]
platform: Win32

Opera 7.54 (Identify as MSIE 6.0) (Linux)

appCodeName: Mozilla
appName: Microsoft Internet Explorer
appVersion: 4.0 (compatible; MSIE 6.0; X11; Linux i686)
userAgent: Mozilla/4.0 (compatible; MSIE 6.0; X11; Linux i686) Opera 7.54 [en]
platform: Linux

Netscape 7.1 (Windows XP)

appCodeName: Mozilla
appName: Netscape
appVersion: 5.0 (Windows; en-US)
userAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)
platform: Win32

Safari 8.0 Mobile (iPad 3rd generation)

appCodeName: Mozilla
appName: Netscape
appVersion: 5.0 (iPad; CPU OS 8_1_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B440 Safari/600.1.4
userAgent:Mozilla/5.0 (iPad; CPU OS 8_1_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B440 Safari/600.1.4
platform: iPad

Safari 5.05 (Windows 7)

appCodeName: Mozilla
appName: Netscape
appVersion: 5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1
userAgent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1
platform: Win32

Safari 3.1 (Windows XP)

appCodeName: Mozilla
appName: Netscape
appVersion: 5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Version/3.1 Safari/525.13
userAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Version/3.1 Safari/525.13
platform: Win32

Safari 1.2.4 (Mac Panther 10.3.7)

appCodeName: Mozilla
appName: Netscape
appVersion: 5.0 (Macintosh; U; PPC Mac OS X; en) appleWebKit/125.5.5 (KHTML, like Gecko) Safari/125.12
userAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) appleWebKit/125.5.5 (KHTML, like Gecko) Safari/125.12
platform: MacPPC

Mozilla 1.7 (Mac Panther 10.3.7)

appCodeName: Mozilla
appName: Netscape
appVersion: 5.0 (Macintosh; en-US)
userAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7) Gecko/20040616
platform: MacPPC

AOL 10.3 (Mac Panther 10.3.7)

appCodeName: Mozilla
appName: Netscape
appVersion: 5.0 (Macintosh; en-US)
userAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US; rv:1.0.2) Gecko/20020924 AOL/7.0
platform: MacPPC

Konqueror 3.3.1

appCodeName: Mozilla
appName: Konqueror
appVersion: 5.0 (compatible; Konqueror/3.3; Linux 2.4.27; X11) (KHTML, like Gecko)
userAgent: Mozilla/5.0 (compatible; Konqueror/3.3; Linux 2.4.27; X11) (KHTML, like Gecko)
platform: Linux i686 X11

Konqueror 3.2.2 (Linux)

appCodeName: Mozilla
appName: Konqueror
appVersion: 5.0 (compatible; Konqueror/3.2; Linux 2.4.26; X11) (KHTML, like Gecko)
userAgent: Mozilla/5.0 (compatible; Konqueror/3.2; Linux 2.4.26; X11) (KHTML, like Gecko)
platform: Linux i686 X11

Methods

Note: "[]" surrounding a parameter below means the parameter is optional.

Methods Description
javaEnabled() Tests whether Java is enabled. Returns Boolean.
plugins.refresh([reload]) Makes newly installed plug-ins available and optionally reloads open documents that contain plug-ins if "reload" argument is present and set to true.

Example 1- Detecting various versions of IE

<script type="text/javascript">
//userAgent in IE7 WinXP returns: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)
//userAgent in IE11 Win7 returns: Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko

if (navigator.userAgent.indexOf('MSIE') != -1)
 var detectIEregexp = /MSIE (\d+\.\d+);/ //test for MSIE x.x
else // if no "MSIE" string in userAgent
 var detectIEregexp = /Trident.*rv[ :]*(\d+\.\d+)/ //test for rv:x.x or rv x.x where Trident string exists

if (detectIEregexp.test(navigator.userAgent)){ //if some form of IE
 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (ieversion>=12)
  document.write("You're using IE12 or above")
 else if (ieversion>=11)
  document.write("You're using IE11 or above")
 else if (ieversion>=10)
  document.write("You're using IE10 or above")
 else if (ieversion>=9)
  document.write("You're using IE9 or above")
 else if (ieversion>=8)
  document.write("You're using IE8 or above")
 else if (ieversion>=7)
  document.write("You're using IE7.x")
 else if (ieversion>=6)
  document.write("You're using IE6.x")
 else if (ieversion>=5)
  document.write("You're using IE5.x")
}
else{
 document.write("n/a")
}
</script>

Output:

Example 2- Detecting various versions of Firefox

<script type="text/javascript">
//Note: userAgent in FF2.0.0.13 WinXP returns: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13
// userAgent in FF35 Win7 returns: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0

if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
 var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (ffversion>=35)
document.write("You're using FF 35 or above")
 else if (ffversion>=5)
document.write("You're using FF 5.x or above")
 else if (ffversion>=4)
document.write("You're using FF 4.x or above")
 else if (ffversion>=3)
document.write("You're using FF 3.x or above")
 else if (ffversion>=2)
document.write("You're using FF 2.x")
 else if (ffversion>=1)
document.write("You're using FF 1.x")
}
else
 document.write("n/a")

</script>

Output:

Example 3- Detecting various versions of Opera starting from Opera 15 (the version when Opera switched its rendering engine to use Chromium)

<script type="text/javascript">
//Note: userAgent in Opera 25 Win7 returns: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36 OPR/25.0.1614.50

var opera15andabovever = /OPR\/(\d+\.\d+)/i.test(navigator.userAgent) // test and capture Opera 15+ version
if (opera15andabovever){
 var operaver = new Number(RegExp.$1) // contains exact Opera15+ version, such as 25 for Opera 25.0
 document.write("You're using Opera" + operaver)
}
else{
 document.write("n/a")
}
</script>

Output:

Reference List

Right column

CopyRight (c) 2018 JavaScript Kit. NO PART may be reproduced without author's permission. Contact Info