JavaScript 1.1: added
JavaScript 1.2: added |
navigator object.
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.
| Property |
Description
|
|
|
|
| Indicates the machine type for which the Navigator was compiled.
|
| |
|---|
| Method |
Description
|
| Allows a signed script to get and set certain Navigator preferences.
|
| |
|---|
watch and unwatch methods from Object.
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
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
appVersion property specifies version information in the following format:
releaseNumber (platform; country)
The values contained in this format are the following:
releaseNumber is the version number of the Navigator. For example, "2.0b4" specifies Navigator 2.0, beta 4.platform is the platform upon which the Navigator is running. For example, "Win16" specifies a 16-bit version of Windows such as Windows 3.1.country is either "I" for the international release, or "U" for the domestic U.S. release. The domestic release has a stronger encryption feature than the international release.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>
javaEnabled()
javaEnabled returns true if Java is enabled; otherwise, false. The user can enable or disable Java by through user preferences.
function1 if Java is enabled; otherwise, it executes function2.
if (navigator.javaEnabled()) {
function1()
}
else function2()
navigator.appCodeName, navigator.appName, navigator.userAgent
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
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)If you supply true,
navigator.plugins.refresh(false)
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.
navigator.plugins.refresh(true)See also the examples for the
Plugin object.
preference(prefName[, setValue])
prefName | |
setValue | The value you want to assign to the preference. This can be a string, number, or Boolean. |
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
prefs.js.UniversalPreferencesWrite privilege. For information on security, see the Client-Side JavaScript Guide.
SavePreferences()
prefs.js settings file. Navigator also saves preferences automatically when it exits.
preference
navigator.taintEnabled()
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.
if (navigator.taintEnabled()) {
function1()
}
else function2()
taint, untaint
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)
Last Updated: 05/28/99 11:59:59