Section 25.207. Navigator: information about the browser in use


25.207. Navigator: information about the browser in use

JavaScript 1.0: Object Navigator

25.207.1. Synopsis

 navigator 

25.207.2. Properties


appCodeName

A read-only string that specifies the code name of the browser. In all browsers based on the Netscape code base (Netscape, Mozilla, Firefox), this is "Mozilla". For compatibility, this property is "Mozilla" in Microsoft browsers as well.


appName

A read-only string property that specifies the name of the browser. For Netscape-based browsers, the value of this property is "Netscape". In IE, the value of this property is "Microsoft Internet Explorer". Other browsers may identify themselves correctly or spoof another browser for compatibility.


appVersion

A read-only string that specifies version and platform information for the browser. The first part of this string is a version number. Pass the string to parseInt( ) to obtain only the major version number or to parseFloat( ) to obtain the major and minor version numbers as a floating-point value. The remainder of the string value of this property provides other details about the browser version, including the operating system it is running on. Unfortunately, however, the format of this information varies widely from browser to browser.


cookieEnabled

A read-only boolean that is true if the browser has cookies enabled and false if they are disabled.


mimeTypes[]

An array of MimeType objects, each of which represents one of the MIME types (e.g., "text/html" and "image/gif") supported by the browser. This array may be indexed numerically or by the name of the MIME type. The mimeTypes[] array is defined by Internet Explorer but is always empty because IE does not support the MimeType object.


platform

A read-only string that specifies the operating system and/or hardware platform on which the browser is running. Although there is no standard set of values for this property, some typical values are "Win32", "MacPPC", and "Linux i586".


plugins[]

An array of Plugin objects, each of which represents one plug-in that is installed in the browser. The Plugin object provides information about the plug-in, including a list of MIME types it supports.

The plugins[] array is defined by Internet Explorer but is always empty because IE does not support the Plugin object.


userAgent

A read-only string that specifies the value the browser uses for the user-agent header in HTTP requests. Typically, this is the value of navigator.appCodeName followed by a slash and the value of navigator.appVersion. For example:

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

25.207.3. Functions


navigator.javaEnabled( )

Tests whether Java is supported and enabled in the current browser.

25.207.4. Description

The Navigator object contains properties that describe the web browser in use. You can use its properties to perform platform-specific customization. The name of this object obviously refers to the Netscape Navigator browser, but all browsers that implement JavaScript support this object as well. There is only a single instance of the Navigator object, which you can reference through the navigator property of any Window object.

Historically, the Navigator object has been used for "client sniffing" to run different code depending on what browser was in use. Example 14-3 shows a simple way to do this, and the accompanying text describes the many pitfalls of relying on the Navigator object. A better approach to cross-browser compatibility is described in Section 13.6.3.

25.207.5. See Also

MimeType, Plugin




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net