The Window object contains references to three objects that contain information about the browser or the browser window itself, rather than information about the contents of the window:
The Window.navigator property refers to a Navigator object which contains information about the web browser as a whole (such as the version, and the list of data formats it can display). The Navigator object is named after Netscape Navigator, obviously, but it is also supported (although only partially) by Internet Explorer.
The Navigator object has four properties that provide version information about the browser that is running. The appName property contains the name of the browser. The appVersion property contains information about the version number and platform of the browser. The userAgent property contains the string that the browser sends in its USER-AGENT header in HTTP requests. Finally, the appCodeName property contains the "code name" of the browser, which, in general is not particularly useful. Each of these properties is a string in human-readable format, so extracting version information can be a little tricky. See the reference pages for details on the string formats.
In Navigator 3.0, the Navigator object also defines two methods that provide further information about the capabilities of the browser. javaEnabled() returns true if the browser supports Java, and if it is enabled; otherwise it returns false. Similarly, taintEnabled() returns true if and only if the browser supports a data-tainting security model, and if that model is enabled.
The remaining two properties of the Navigator object are the mimeTypes array and the plugins array, which specify the data types that the browser can display and the plug-ins that are installed. These arrays are only available in Navigator 3.0. The subsections below contain more details on these arrays.
We saw above that the Navigator object has four properties that contain information about the browser version. This information is useful when you need to work around bugs in particular versions, or make use of special features found in one browser but not another, for example. Unfortunately, it can be a little difficult to access the information in a convenient way. Example 13.1 shows how you can use the Navigator object to determine what browser is being used, what version of that browser, and what platform it is running on. The code in this example stores the information in more convenient properties of a new browser object.
In Navigator 3.0, the navigator.mimeTypes property is an array of MimeType objects, each of which describe one MIME data format ("text/html", and "image/gif", for example) that the web browser can display (either directly, with an external helper application, or with a plug-in.) The MimeType object itself contains properties that describe the data format.
The mimeTypes array is indexed numerically, but is also an associative array, indexed by the name of the MIME type. Thus, you can easily check for support of a given data format on the browser:
// Check to see if the browser can display MPEG files. var show_movie = (navigator.mimeTypes["video/mpeg"] != null);
If you want to determine whether a given MIME type is supported by a plug-in (instead of a helper application, for example), you can examine the enabledPlugin property of the MimeType object. If it is null, then no plug-in supports the object. Otherwise, this property refers to a Plugin object that represents the plug-in that is configured to display data of the specified format.
In Navigator 3.0, the navigator.plugins property is an array of Plugin objects, each of which represents one plug-in module that has been installed in the browser. The properties of the Plugin object provide various details about the plug-in. The Plugin object also contains array elements, which are a MimeType objects describing each of data formats supported by that particular plug-in. Note that this array is different than the navigator.mimeTypes array described above.
You can use the plugins property as an associative array, just as you can the mimeTypes property. This lets you check for the existence of a particular plug-in without having to loop through the array numerically and check every element:
// Check to see if the browser has the Shockwave plug-in installed. var shocked = (navigator.plugins["Shockwave"] != null);