JavaScript Kit > JavaScript Reference > Here
Navigator Object
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, if (window.addEventListener){ |
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
Revew the example section further below
to see how to detect various versions of IE using You can probe the //returns true if user is using one of the following mobile browsers |
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:
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:
- JavaScript Operators
- JavaScript Statements
- Global functions
- JavaScript Events
- Escape Sequences
- Reserved Words