Categories:

JavaScript Kit > JavaScript Reference > Here

Navigator Object

Last updated: July 4th, 2011

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

Related Tutorials

Properties

Properties Description
appCodeName The code name of the browser.
appName The name of the browser (ie: Microsoft Internet Explorer).
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.
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. (ie: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1;)

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 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 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 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 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 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">
//note: userAgent in IE7 WinXP returns: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)

if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 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

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>=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

<script type="text/javascript">
//Note: userAgent in Opera9.24 WinXP returns: Opera/9.24 (Windows NT 5.1; U; en)
//         userAgent in Opera 8.5 (identified as IE) returns: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Opera 8.50 [en]
//         userAgent in Opera 8.5 (identified as Opera) returns: Opera/8.50 (Windows NT 5.1; U) [en]

if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Opera/x.x or Opera x.x (ignoring remaining decimal places);
 var oprversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (oprversion>=10)
  document.write("You're using Opera 10.x or above")
 else if (oprversion>=9)
  document.write("You're using Opera 9.x")
 else if (oprversion>=8)
  document.write("You're using Opera 8.x")
 else if (oprversion>=7)
  document.write("You're using Opera 7.x")
 else
  document.write("n/a")
}
else
 document.write("n/a")
</script>

Output:

Reference List

Partners
Right column

CopyRight 1998-2014 JavaScript Kit. NO PART may be reproduced without author's permission.