Table of Contents | Previous
| Next
| Index
Contains information about the version of Navigator in use.
The JavaScript runtime engine on the client automatically creates the navigator object.
Use the navigator object to determine which version of the Navigator your users have, what MIME types the user's Navigator can handle, and what plug-ins the user has installed. All of the properties of the navigator object are read-only.
In addition, this object inherits the watch and unwatch methods from Object.
A string specifying the code name of the browser.
The following example displays the value of the appCodeName property:
document.write("The value of navigator.appCodeName is " + navigator.appCodeName)
For Navigator 2.0 and later, this displays the following:
The value of navigator.appCodeName is Mozilla
A string specifying the name of the browser.
The following example displays the value of the appName property:
document.write("The value of navigator.appName is " + navigator.appName)
For Navigator 2.0 and 3.0, this displays the following:
The value of navigator.appName is Netscape
A string specifying version information for the Navigator.
The appVersion property specifies version information in the following format:
releaseNumber (platform; country)
The values contained in this format are the following:
Example 1. The following example displays version information for the Navigator:
document.write("The value of navigator.appVersion is " + navigator.appVersion)
For Navigator 2.0 on Windows 95, this displays the following:
The value of navigator.appVersion is 2.0 (Win95, I)
For Navigator 3.0 on Windows NT, this displays the following:
The value of navigator.appVersion is 3.0 (WinNT, I)
Example 2. The following example populates a Textarea object with newline characters separating each line. Because the newline character varies from platform to platform, the example tests the appVersion property to determine whether the user is running Windows (appVersion contains "Win" for all versions of Windows). If the user is running Windows, the newline character is set to \r\n; otherwise, it's set to \n, which is the newline character for Unix and Macintosh.
NOTE:
This code is needed only for JavaScript 1.0. JavaScript versions 1.1 and later
check for all newline characters before setting a string-valued property and
translate them as needed for the user's platform.
<SCRIPT> var newline=null function populate(textareaObject){ if (navigator.appVersion.lastIndexOf('Win') != -1) newline="\r\n" else newline="\n" textareaObject.value="line 1" + newline + "line 2" + newline + "line 3" } </SCRIPT> <FORM NAME="form1"> <BR><TEXTAREA NAME="testLines" ROWS=8 COLS=55></TEXTAREA> <P><INPUT TYPE="button" VALUE="Populate the Textarea object" onClick="populate(document.form1.testLines)"> </TEXTAREA> </FORM>
Tests whether Java is enabled.
javaEnabled()
None.
javaEnabled returns true if Java is enabled; otherwise, false. The user can enable or disable Java by through user preferences.
The following code executes function1 if Java is enabled; otherwise, it executes function2.
if (navigator.javaEnabled()) { function1() } else function2()
navigator.appCodeName, navigator.appName, navigator.userAgent
Indicates the translation of the Navigator being used.
The value for language is usually a 2-letter code, such as "en" and occasionally a five-character code to indicate a language subtype, such as "zh_CN".
Use this property to determine the language of the Navigator client software being used. For example you might want to display translated text for the user.
An array of all MIME types supported by the client.
The mimeTypes array contains an entry for each MIME type supported by the client (either internally, via helper applications, or by plug-ins). For example, if a client supports three MIME types, these MIME types are reflected as navigator.mimeTypes[0], navigator.mimeTypes[1], and navigator.mimeTypes[2].
Each element of the mimeTypes array is a MimeType object.
To obtain the number of supported mime types, use the length property: navigator.mimeTypes.length.
MimeType
Indicates the machine type for which the Navigator was compiled.
Platform values are Win32, Win16, Mac68k, MacPPC and various Unix.
The machine type the Navigator was compiled for may differ from the actual machine type due to version differences, emulators, or other reasons.
If you use SmartUpdate to download software to a user's machine, you can use this property to ensure that the trigger downloads the appropriate JAR files. The triggering page checks the Navigator version before checking the platform property. For information on using SmartUpdate, see Using JAR Installation Manager for SmartUpdate.
An array of all plug-ins currently installed on the client.
You can refer to the Plugin objects installed on the client by using this array. Each element of the plugins array is a Plugin object. For example, if three plug-ins are installed on the client, these plug-ins are reflected as navigator.plugins[0], navigator.plugins[1], and navigator.plugins[2].
To use the plugins array:
1. navigator.plugins[index] 2. navigator.plugins[index][mimeTypeIndex]
index is an integer representing a plug-in installed on the client or a string containing the name of a Plugin object (from the name property). The first form returns the Plugin object stored at the specified location in the plugins array. The second form returns the MimeType object at the specified index in that Plugin object.
To obtain the number of plug-ins installed on the client, use the length property: navigator.plugins.length.
plugins.refresh.
The plugins array has its own method, refresh. This method makes newly installed plug-ins available, updates related arrays such as the plugins array, and optionally reloads open documents that contain plug-ins. You call this method with one of the following statements:
navigator.plugins.refresh(true) navigator.plugins.refresh(false)
If you supply true, refresh refreshes the plugins array to make newly installed plug-ins available and reloads all open documents that contain embedded objects (EMBED tag). If you supply false, it refreshes the plugins array, but does not reload open documents.
When the user installs a plug-in, that plug-in is not available until refresh is called or the user closes and restarts Navigator.
The following code refreshes arrays and reloads open documents containing embedded objects:
navigator.plugins.refresh(true)
See also the examples for the Plugin object.
Allows a signed script to get and set certain Navigator preferences.
preference(prefName[, setValue])
This method returns the value of the preference. If you use the method to set the value, it returns the new value.
With permission, you can get and set the preferences shown in the following table.
Table 1.2 Preferences.
Reading a preference with the preference method requires the UniversalPreferencesRead privilege. Setting a preference with this method requires the UniversalPreferencesWrite privilege. For information on security, see the Client-Side JavaScript Guide.
savePreferences
Saves the Navigator preferences to the local file prefs.js.
Saving user preferences requires the UniversalPreferencesWrite privilege. For information on security, see the Client-Side JavaScript Guide.
SavePreferences()
This method immediately saves the current Navigator preferences to the user's prefs.js settings file. Navigator also saves preferences automatically when it exits.
preference
Specifies whether data tainting is enabled.
navigator.taintEnabled()
Tainting prevents other scripts from passing information that should be secure and private, such as directory structures or user session history. JavaScript cannot pass tainted values on to any server without the end user's permission.
Use taintEnabled to determine if data tainting is enabled. taintEnabled returns true if data tainting is enabled, false otherwise. The user enables or disables data tainting by using the environment variable NS_ENABLE_TAINT.
The following code executes function1 if data tainting is enabled; otherwise it executes function2.
if (navigator.taintEnabled()) { function1() } else function2()
taint, untaint
A string representing the value of the user-agent header sent in the HTTP protocol from client to server.
Servers use the value sent in the user-agent header to identify the client.
The following example displays userAgent information for the Navigator:
document.write("The value of navigator.userAgent is " + navigator.userAgent)
For Navigator 2.0, this displays the following:
The value of navigator.userAgent is Mozilla/2.0 (Win16; I)
Table of Contents | Previous
| Next
| Index
Last Updated: 05/28/99 11:59:59
Copyright (c) 1999
Netscape Communications Corporation
|