JavaScript Kit > JavaScript Reference > Here
Navigator Object
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: 4.75 [en] (Win98; U)). |
| 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. |
| 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/4.0 (compatible; MSIE 6.0; Windows NT 5.1)) |
| 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">
//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>=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>=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:
- JavaScript Operators
- JavaScript Statements
- Global functions
- Escape Sequences
- Reserved Words
- Ajax (XMLHttpRequest)
- Anchor
- Applet
- Area
- Array
- Boolean
- Date
- Document
- Event
- Form
- Reset
- Frame
- Function
- History
- Image
- Link
- Location
- Math
- Navigator
- Number
- Object
- RegExp
- Screen
- String
- Style
- window

