Navigator object (Object/browser)

An object that contains properties that describe the browser (a.k.a. user agent or client).

Availability:

JavaScript - 1.0
JScript - 1.0
Internet Explorer - 3.02
Netscape - 2.0
Opera - 3.0
JavaScript syntax:-myWindow.navigator
-navigator
Object properties:appCodeName, appMinorVersion, appName, appVersion, browserLanguage, constructor, cookieEnabled, cpuClass, language, onLine, opsProfile, platform, securityPolicy, systemLanguage, userAgent, userLanguage, userProfile
Object methods:javaEnabled(), plugins, preference(), savePreferences(), taintEnabled()
Collections:mimeTypes[], plugins[]

The navigator object is named after Netscape Navigator but is also present in other browsers since it has become the de facto standard way of enquiring as to a browser's provenance.

You can inspect the various properties belonging to the navigator object and establish the name and type of the browser, its version and the platform it is running on.

The navigator object is available as a property of the window and also the Global object but it will be the same navigator object. There is only one and you cannot instantiate another.

As this object is persistent, you might add properties to it that can be passed from window to window. However this will only work on Netscape, because MSIE seems to initialize a new navigator object for each window. MSIE does allow you to add properties to navigator object but they are private to that window. Netscape shares them across windows. The example shows how to make this work.

You can accomplish the same thing in a cross browser portable manner by using a frameset and storing properties in the top level frameset's Global object. You can also (if security allows) write scripts to communicate between windows, in which case you may need to make sure the scripts are aware of multiple document objects as well as windows. This can get tricky and you may need to make sure the scripts run in the correct windows and return a value to a caller. This should ensure they run in the correct scope.

Netscape 6.0 provides a sidebar which you should expect to be persistent. There's a similar sidebar in MSIE too. Netscape clearly intends you to script its sidebar but right now the implementation is a bit buggy. It might be too much to hope for, but digging into the internals of these suggests that RDF is involved, which may point to some commonality. Maybe we will be able to use the sidebar in the browsers as a repository for session storage, or persistent values that we can access from script, but it's not there and working yet.

Warnings:

Example code:

   <!-- Save this in navigator.html -->
   <HTML>
   <HEAD></HEAD>
   <BODY>
   <SCRIPT>
   navigator.myNewProperty = "session global value";
   open("navigator1.html")
   </SCRIPT>
   </BODY>
   </HTML>
   ---------------------------------------------------------------
   <!-- Save this in  navigator1.html -->
   <HTML>
   <HEAD></HEAD>
   <BODY>
   <SCRIPT>
   document.write(navigator.myNewProperty);
   </SCRIPT>
   </BODY>
   </HTML>

See also:Cross platform compatibility, Window.navigator

PropertyJavaScriptJScriptN IEOperaNESECMADOMCSSHTMLNotes
appCodeName1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aReadOnly.
appMinorVersion n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning , ReadOnly.
appName1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aReadOnly.
appVersion1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aReadOnly.
browserLanguage n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning , ReadOnly.
constructor1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning
cookieEnabled1.5 1.53.0 3.06.0 6.04.0 4.0 n/a n/a n/a n/a n/a n/aReadOnly.
cpuClass n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aReadOnly.
language1.2 1.2 n/a4.0 4.0 n/a5.0 5.0 n/a n/a n/a n/a n/aWarning , ReadOnly.
onLine n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aReadOnly.
opsProfile n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/aWarning , ReadOnly.
platform1.2 1.23.0 3.04.0 4.04.0 4.05.0 5.0 n/a n/a n/a n/a n/aReadOnly.
securityPolicy1.4 1.4 n/a4.7 4.7 n/a n/a n/a n/a n/a n/a n/aWarning , ReadOnly.
systemLanguage n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning , ReadOnly.
userAgent1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aWarning , ReadOnly.
userLanguage n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning , ReadOnly.
userProfile n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aReadOnly.

MethodJavaScriptJScriptN IEOperaNESECMADOMCSSHTMLNotes
javaEnabled()1.1 1.13.0 3.03.0 3.04.0 4.03.0 3.0 n/a n/a n/a n/a n/a-
plugins1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aWarning
preference()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a n/a n/a n/a n/aWarning
savePreferences()1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning
taintEnabled()1.1 1.13.0 3.03.0 3.04.0 4.0 5.0 5.0 n/a n/a n/a n/a n/aWarning , Deprecated