Client-side object | |
Implemented in |
Navigator 2.0 Navigator 3.0: added mimeTypes and plugins properties; added javaEnabled and taintEnabled methods.Navigator 4.0: added language and platform properties; added preference method.
|
Created by
The JavaScript runtime engine on the client automatically creates the navigator
object.
Description
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.
Property Summary
Properties
appCodeName
A string specifying the code name of the browser.
Property of |
navigator
|
Read-only | |
Implemented in | Navigator 2.0 |
Examples
The following example displays the value of the appCodeName
property:
document.write("The value of navigator.appCodeName is " +
For Navigator 2.0 and 3.0, this displays the following:
navigator.appCodeName)The value of navigator.appCodeName is Mozilla
appName
A string specifying the name of the browser.
Property of |
navigator
|
Read-only | |
Implemented in | Navigator 2.0 |
Examples
The following example displays the value of the appName
property:
document.write("The value of navigator.appName is " +
For Navigator 2.0 and 3.0, this displays the following:
navigator.appName)The value of navigator.appName is Netscape
appVersion
A string specifying version information for the Navigator.
Property of |
navigator
|
Read-only | |
Implemented in | Navigator 2.0 |
Description
The appVersion
property specifies version information in the following format:
releaseNumber
(platform
; country
)
The values contained in this format are the following:
document.write("The value of navigator.appVersion is " +For Navigator 2.0 on Windows 95, this displays the following:
navigator.appVersion)
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.
<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>
Property of |
navigator
|
Read-only | |
Implemented in | Navigator 4.0 |
Description
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.
mimeTypes
An array of all MIME types supported by the client.
Property of |
navigator
|
Read-only | |
Implemented in | Navigator 3.0 |
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.
platform
Indicates the machine type for which the Navigator was compiled.
Property of |
navigator
|
Read-only | |
Implemented in | Navigator 4.0 |
Description
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.
plugins
An array of all plug-ins currently installed on the client.
Property of |
navigator
|
Read-only | |
Implemented in | Navigator 3.0 |
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)
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.
Examples
The following code refreshes arrays and reloads open documents containing embedded objects:
navigator.plugins.refresh(true)
See also the examples for the Plugin
object.
userAgent
A string representing the value of the user-agent header sent in the HTTP protocol from client to server.
Property of |
navigator
|
Read-only | |
Implemented in | Navigator 2.0 |
Description
Servers use the value sent in the user-agent header to identify the client.
Examples
The following example displays userAgent
information for the Navigator:
document.write("The value of navigator.userAgent is " +
For Navigator 2.0, this displays the following:
navigator.userAgent)The value of navigator.userAgent is Mozilla/2.0 (Win16; I)
Methods
javaEnabled
Tests whether Java is enabled.
Method of |
navigator
|
Static | |
Implemented in | Navigator 3.0 |
Syntax
javaEnabled()
Parameters
None.
Description
javaEnabled
returns true if Java is enabled; otherwise, false. The user can enable or disable Java by through user preferences.
Examples
The following code executes function1
if Java is enabled; otherwise, it executes function2
.
if (navigator.javaEnabled()) {
function1()
}
else function2() See also
navigator.appCodeName
, navigator.appName
, navigator.userAgent
preference
Allows a signed script to get and set certain Navigator preferences.
Method of |
navigator
|
Static | |
Implemented in | Navigator 4.0 |
Syntax
preference(prefName)
preference(prefName, setValue) Parameters
Description
This method returns the value of the preference. If you use the method to set the value, it returns the new value.
Security
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 in Navigator 4.0, see Chapter 7, "JavaScript Security," in the JavaScript Guide.
With permission, you can get and set the preferences shown in Table 8.2.
taintEnabled
Specifies whether data tainting is enabled.
Method of |
navigator
|
Static | |
Implemented in | Navigator 3.0; removed in Navigator 4.0 |
Syntax
navigator.taintEnabled()
Description
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
.
Examples
The following code executes function1 if data tainting is enabled; otherwise it executes function2.
if (navigator.taintEnabled()) {
function1()
}
else function2() See also
taint
, untaint
Last Updated: 10/31/97 12:32:33