navigatorNN 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.

 
 
Object Model Reference
NN navigator
IE navigator
appCodeNameNN 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 both companies' browsers return this code name.

 
Example
var codeName = navigator.appCodeName
 
Value
Mozilla
 
Default Mozilla
appMinorVersionNN n/a   IE 4   DOM n/a
 Read-only
 

Reveals the value to the right of the decimal point in the entire version number. So-called bug-fix or patched versions, such as 4.03, are not reflected in IE's version numbering, so they return a value of 0. The exact release version is available by parsing the values of appVersion or userAgent.

 
Example
var subVer = navigator.appMinorVersion
 
Value
String version of the first digit to the right of the decimal of the primary version number.
 
Default Depends on browser version.
appNameNN 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
 
Default Depends on browser.
appVersionNN 2   IE 3   DOM n/a
 Read-only
 

Reveals the version number of the browser, along with minimal operating system platform information (a subset of the information returned by userAgent). The first word of the value returned by Navigator includes the version number down to the x.xx level, whereas Internet Explorer goes only to the x.x level. In parentheses, both browsers include operating system information and (for Navigator) the browser's default language version. Sample returned values are as follows:

Navigator:

4.04 [en] (Win95; I)
4.03 (Macintosh; I; PPC)

Internet Explorer:

4.0 (compatible; MSIE 4.01; Windows 95)
4.0 (compatible; MSIE 4.0; Macintosh; I; PPC)

You can use parseInt( ) on this value to determine whether a browser is of a particular generation, as shown in the following example. This extracts the integer value, which can be used in a math comparison operation to find out whether the browser is at a minimum needed version level for a script to run.

 
Example
var isVer4Min = parseInt(navigator.appVersion) >= 4
 
Value
String values.
 
Default Depends on browser.
browserLanguageNN n/a   IE 4   DOM n/a
 Read-only
 

The default written language of the browser. The Navigator 4 equivalent is the navigator.language property.

 
Example
var browLangCode = navigator.browserLanguage
 
Value
Case-insensitive language code as a string.
 
Default Browser default.
cookieEnabledNN n/a   IE 4   DOM n/a
 Read-only
 

Returns whether the browser allows reading and writing of cookie data.

 
Example
if (cookieEnabled) {
    setCookieData(data)
}
 
Value
Boolean value: true | false.
 
Default Depends on browser setting.
cpuClassNN 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 value.
 
Default Depends on client hardware.
languageNN 4   IE n/a   DOM n/a
 Read-only
 

The written language for which the browser version was created. The language is specified in the ISO 639 language code scheme. 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.
onLineNN n/a   IE 4   DOM n/a
 Read-only
 

Whether the browser is set for online or offline browsing (in Internet Explorer 4'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
platformNN 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( ) content suitable for a Windows 95/NT computer
}
 
Value
String.
 
Default None.
systemLanguageNN n/a   IE 4   DOM n/a
 Read-only
 

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).
userAgentNN 2   IE 3   DOM n/a
 Read-only
 

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 data. Typical data for this property looks like the following:

Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)

Do not rely on the length or position of any part of this data, as it may vary with browser, version, and proxy server used at the client end. Instead, use the indexOf( ) method to check for the presence of a desired string.

 
Example
if (navigator.userAgent.indexOf("MSIE") != -1) {
    var isIE = true
}
 
Value
String.
 
Default Depends on browser.
userLanguageNN 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.
userProfileNN 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 4). 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.
javaEnabled( )NN 3   IE 4   DOM n/a

Returns whether Java is turned on in the browser. This property won't help you in a non-scriptable browser (or scriptable browser that doesn't support the property), but it does tell you whether the user has Java turned off in the browser preferences.

 
Returned Value
Boolean value: true | false.
 
Parameters
None.
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 enterprisewide deployment of Navigator. Consult the Netscape developer web site for further information about these preferences settings (http://developer.netscape.com/library/documentation/deplymt/jsprefs.htm).

 
Returned Value
Preference value in a variety of data types.
 
Parameters
name The preference name as a string, such as general.always_load_images.
value An optional value to set the named preference.
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 4 also includes it for compatibility, even though it always returns false.

 
Returned Value
Boolean value: true | false.
 
Parameters
None.