navigator | NN 2 IE 3 DOM n/a | |||||||||||||||||||||||
The navigator object in many ways represents the browser application. As such, the browser is outside the scope of the document object model. Even so, the navigator object plays an important role in scripting, because it allows scripts to see what browser and browser version is running the script. In addition to several key properties that both Navigator and Internet Explorer have in common, each browser also extends the property listing of this object in ways that would generally benefit all browsers. IE duplicates this object under the clientInformation object name, but for cross-browser compatibility, you can use the navigator object reference in all browsers. |
||||||||||||||||||||||||
Object Model Reference | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
Object-Specific Properties | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
Object-Specific Methods | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
Object-Specific Event Handler Properties | ||||||||||||||||||||||||
None. |
appCodeName | NN 2 IE 3 DOM n/a |
Read-only | |
Reveals the code name of the browser. Both Navigator and Internet Explorer return Mozilla, which was the code name for an early version of Navigator (a combination of the early freeware name of the Mosaic browser and Godzilla). The Mozilla character is Netscape's corporate mascot, but all browsers that license the original Mosaic technology (including IE) return Mozilla. |
|
Example | |
var codeName = navigator.appCodeName; |
|
Value | |
Mozilla |
|
Default | |
Mozilla |
appMinorVersion | NN n/a IE 4 DOM n/a |
Read-only | |
With succeeding generations of Internet Explorer, this property returns a dizzying range of values, most of which are not useful for typical version detection. IE 5.x for Windows returns an appVersion value of 4.0, with the appMinorVersion reporting the first digit to the right of the decimal. In IE 6 for Windows, the appMinorVersion returns a string signifying a build or patch code number, such as ;Q313675;. Use with extreme caution. |
|
Example | |
var subVer = navigator.appMinorVersion; |
|
Value | |
String. |
|
Default | |
Depends on browser version. |
appName | NN 2 IE 3 DOM n/a |
Read-only | |
Reveals the model name of the browser. |
|
Example | |
var isNav = navigator.appName == "Netscape"; |
|
Value | |
String values. NN: "Netscape"; IE: "Microsoft Internet Explorer". Some other browsers return these values to appear to be compatible with one of the mainstream browsers. |
|
Default | |
Depends on browser. |
appVersion | NN 2 IE 3 DOM n/a |
Read-only | |
Reveals a version number of the browser engine, along with minimal operating system platform information (a subset of the information returned by userAgent). Sample returned values are as follows. |
|
Internet Explorer: 4.0 (compatible; MSIE 6.0; Windows 98; Q312461) 4.0 (compatible; MSIE 5.0; Macintosh; I; PPC) |
|
Navigator: 4.04 [en] (Win95; I) 5.0 (Macintosh; en-US) |
|
Note that the version number at the start of the value (up to the first whitespace) is not indicative of the actual browser application version, but rather of the fundamental engine. Thus, IE application Versions 4 through 6 (and perhaps later) all report engine Version 4.0; Netscape 6 is based on what it terms engine generation 5.0. Browser application version information is found elsewhere either in the appVersion, userAgent, or other navigator object properties. Do not use the first word of the appVersion value for any kind of browser version detection that influences which DOM or JavaScript language features are supported by the browser. In browsers leading up to Version 4, this property correctly reflected the application version, but that is no longer the case. |
|
While it may appear that the precise Internet Explorer version is embedded in this property's value (as MSIE X.XX), there are occasional mismatches in some versions. To inspect this portion of the version string, the navigator.userAgent property is more reliable. |
|
Example | |
var isVer4Min = parseInt(navigator.appVersion) >= 4; |
|
Value | |
String. |
|
Default | |
Depends on browser. |
browserLanguage | NN n/a IE 4 DOM n/a |
Read-only | |
Provides the default written language of the browser. The Navigator equivalent is the navigator.language property. |
|
Example | |
var browLangCode = navigator.browserLanguage; |
|
Value | |
Case-insensitive language code as a string. |
|
Default | |
Browser default. |
cpuClass | NN n/a IE 4 DOM n/a |
Read-only | |
Returns a string reference of the CPU of the client computer. Common Intel microprocessors (including Pentium-class CPUs and Macintoshes running Windows emulators) return x86, while PowerPC Macintoshes return PPC. This value tells you only about the basic hardware class, not the operating system or specific CPU speed or model number. |
|
Example | |
if (navigator.cpuClass == "PPC") { // statements specific to PowerPC clients } |
|
Value | |
String. |
|
Default | |
Depends on client hardware. |
language | NN 4 IE n/a DOM n/a |
Read-only | |
Indicates the written language for which the browser version was created. The language is specified in the ISO 639 language code scheme (such as en-us). Internet Explorer provides this information via the navigator.browserLanguage property. |
|
Example | |
var mainLang = navigator.language; |
|
Value | |
Case-insensitive language code as a string. |
|
Default | |
Browser default. |
mimeTypes | NN 4 IE 5(Mac) DOM n/a |
Read-only | |
Returns an array of mimeType objects supported by installed plugins in the browser. IE for Windows provides this property for syntactical compatibility, but it always returns an array of zero length. See the mimeType object. |
|
Example | |
var videoPlugin = navigator.mimeTypes["video/mpeg"].enabledPlugin; |
|
Value | |
Array of mimeType objects. |
|
Default | |
Browser default. |
onLine | NN n/a IE 4 DOM n/a |
Read-only | |
Specifies whether the browser is set for online or offline browsing (in Internet Explorer's File menu). Pages may wish to invoke live server actions when they load in online mode, but avoid these calls when in offline mode. Use this Boolean property to build such conditional statements. |
|
Example | |
if (navigator.onLine) { document.write("<applet ...>"); ... } |
|
Value | |
Boolean value: true | false. |
|
Default | |
true |
oscpu | NN 6 IE n/a DOM n/a |
Read-only | |
Returns a string containing operating system or central processing unit information about the client machine. Values vary widely across systems. Windows clients are divided roughly into two categories: non-NT and NT. The former includes Windows 95, 98, and ME (oscpu values of Win95, Win98, and Win 9x 4.90, respectively). The NT category includes Windows NT 4 (WinNT4.0) and Windows XP (Windows NT x.x). Macintosh systems all report the CPU type and the absence or presence of Mac OS X (PPC or PPC Mac OS X). Unix systems report both the operating system and CPU type. The oscpu value is also a part of the userAgent value. Formatting for this information is not the same in Internet Explorer's corresponding cpuClass or userAgent properties. |
|
Example | |
if (navigator.oscpu.indexOf("Win") != -1) { document.write("You are running a Windows computer."); } |
|
Value | |
String. |
|
Default | |
System dependent. |
platform | NN 4 IE 4 DOM n/a |
Read-only | |
Returns the name of the operating system or hardware platform of the browser. For Windows 95/NT, the value is Win32; for a Macintosh running a PowerPC CPU, the value is MacPPC. At least for the major platforms I've been able to test, Navigator and Internet Explorer agree on the returned values. Using this property to determine the baseline facilities of the client in a conditional expression can help the page optimize its output for the device. |
|
Example | |
if (navigator.platform == "Win32") { document.write("<link rel='stylesheet' type='text/css' href='css/stylePC.css'>"); } |
|
Value | |
String. |
|
Default | |
System dependent. |
plugins[ ] | NN 3 IE 5(Mac) DOM n/a |
Read-only | |
Returns a collection of plugin objects recognized by the browser to facilitate script determination of the browser's support for a particular external media type. IE 4 and later for Windows implement this property, but only as a dummy placeholder that always returns an array of length zero. See the mimeType and plugin objects. |
|
Example | |
var plugInCount = navigator.plugins.length; |
|
Value | |
Array of plugin object references. |
|
Default | |
None. |
product, productSub | NN 6 IE n/a DOM n/a |
Read-only | |
Return a string identifying the software engine behind the browser. In Netscape 6, the product property returns Gecko, while the productSub property returns a development build number (in string form). |
|
Example | |
var prod = navigator.product; |
|
Value | |
String. |
|
Default | |
Browser dependent. |
securityPolicy | NN 4 IE n/a DOM n/a |
Read-only | |
Returns a string in Navigator 4 revealing the browser's encryption level (that is, the domestic or export encryption policy to which the browser adheres). With the loosening of U.S. encryption export laws, Netscape 6 implements one encryption type across all versions. In Netscape 6, this property returns an empty string. |
|
Value | |
String. |
|
Default | |
None. |
systemLanguage | NN n/a IE 4 DOM n/a |
Read-only | |
Specifies the code for the default written language used by the operating system. If you have multi-lingual content available, you can use this property to insert content in specific languages. |
|
Example | |
if (navigator.systemLanguage == "nl") {
// document.write( ) some Dutch content
}
|
|
Value | |
Case-insensitive language code. |
|
Default | |
Usually the browser default (en for English-language Internet Explorer available in the United States). |
userAgent | NN 2 IE 3 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. |
userLanguage | NN n/a IE 4 DOM n/a |
Read-only | |
The default written language of the browser, based on the operating system user profile setting (if one exists). The property defaults to the browserLanguage property. |
|
Example | |
var userLangCode = navigator.userLanguage; |
|
Value | |
Case-insensitive language code as a string. |
|
Default | |
Browser default. |
userProfile | NN n/a IE 4 DOM n/a |
Read-only | |
The userProfile property is, itself, an object that lets scripts request permission to access personal information stored in the visitor's user profile (for Win32 versions of Internet Explorer). See the userProfile object. |
|
Example | |
navigator.userProfile.addReadRequest("vcard.displayname"); navigator.userProfile.doReadRequest("3", "MegaCorp Customer Service"); var custName = navigator.userProfile.getAttribute("vcard.displayname"); navigator.userProfile.clearRequest( ); if (custName) { ... } |
|
Value | |
userProfile object reference. |
|
Default | |
Browser default. |
vendor, vendorSub | NN 6 IE n/a DOM n/a |
Read-only | |
Return a string identifying the browser product that employs the Mozilla engine. In Netscape 6, the vendor property returns Netscape6, while Netscape 7 returns simply Netscape. The vendorSub property returns the version release in detail (in string form). If you want to test for a minimum version, convert the navigator.vendorSub value to a decimal floating-point number before performing a comparison against your minimum requirement. |
|
Example | |
if (parseFloat(navigator.vendorSub, 10) >= 6.2) { // OK, meets minimum NN requirement } |
|
Value | |
String. |
|
Default | |
Browser dependent. |
javaEnabled( ) | NN 3 IE 4 DOM n/a |
Returns whether Java is turned on in the browser. This method obviously won't help you in a nonscriptable browser (or scriptable browser that doesn't support the property), but if scripting is enabled, it does tell you whether the user has Java turned off in the browser preferences. |
|
Parameters | |
None. |
|
Returned Value | |
Boolean value: true | false. |
preference( ) | NN 4 IE n/a DOM n/a |
preference(name[, value]) | |
By way of signed scripts in Navigator 4, you can access a wide variety of user preferences settings. These include even the most detailed items, such as whether the user has elected to download images or whether style sheets are enabled. Most of these settings are intended for scripts used by network administrators to install and control the user settings of enterprise-wide deployment of Navigator. Consult the Netscape developer web site for further information about these preferences settings (http://developer.netscape.com/docs/manuals/communicator/preferences/). Netscape 6 throws a security exception when invoking this method (even with signed scripts), but the method works with signed scripts in Netscape 7. |
|
Parameters | |
|
|
Returned Value | |
Preference value in a variety of data types. |
taintEnabled( ) | NN 3 IE 4 DOM n/a |
Returns whether data tainting is turned on in the browser. This security mechanism was never fully implemented in Navigator, but the method that checks for it is still included in newer versions of Navigator for backward compatibility. Internet Explorer also includes it for compatibility, even though it always returns false. |
|
Parameters | |
None. |
|
Returned Value | |
Boolean value: true | false. |