JavaScript's Navigator Object

Source: Internet
Author: User

Navigator Object

Reprint: http://www.itlearner.com/code/js_ref/brow1.htm

Contains the version information for the Navigator that is in use.

Client Object
Implementation version Navigator 2.0 Navigator 3.0: Added mimetypes and plugins attributes, added javaenabled and taintenabled methods. Navigator 4.0: Added language and platform attributes; Preference method added.

Create a source

The JavaScript client runs the time engine to automatically create navigator objects.

Describe

Use the Navigator object to determine the version of Navigator that your users are using, and the user's navigator can control the MIME type of the plugin that the user has installed. All of these navigator properties are read-only.

Properties Overview

appCodeName Specifies the code name of the browser.
AppName Specifies the name of the browser.
AppVersion Specifies the version information for the Navigator.
Language Indicates the translation language of the Navigator being used.
Mimetypes An array of all MIME types supported by the client.
Platform Indicates the type of machine the Navigator is compiled for.
Plugins An array of all the plugins that the client has installed.
UserAgent The user agent header is specified.

Method overview

javaenabled Tests whether Java is allowed.
Plugins.refresh Make the newly installed plug-in valid, and optionally reload the open document containing the plug-in.
Preference Allows an identified script to get and set a specific Navigator parameter.
taintenabled Specifies whether to allow data stains.

Property

appCodeName A String that specifies the name of the browser code.

Property source Navigator
Read-only
Implementation version Navigator 2.0

Example the following example shows the value of the appCodeName property:

document.write ("Navigator.appcodename value is" + navigator.appcodename) for Navigator 2.0 and 3.0, this statement displays the following text:

The value of Navigator.appcodename is Mozilla

AppName A String that specifies the name of the browser.

Property source Navigator
Read-only
Implementation version Navigator 2.0

Example the following example shows the value of the AppName property:

document.write ("Navigator.appname value is" + navigator.appname) for Navigator 2.0 and 3.0, this statement displays the following text:

The value of Navigator.appname is Netscape

AppVersion A String that specifies the Navigator version information.

Property source Navigator
Read-only
Implementation version Navigator 2.0

The Description AppVersion property specifies the version information in the following format:

Releasenumber (platform; country)

The following values are included in this format:

      • Releasenumber is the version number of Navigator. For example, "2.0b4
"Navigator 2.0 was specified, Beta 4.

      • Platform is the platform for Navigator to run. For example, "Win16" specifies a 16-bit version of Windows, such as Windows 3.1.

      • Country is "I" for the International Version and "U" for the Native American version. The native version has a stronger encryption feature than the international version.

Example Example 1.The following example shows the version information for Navigator:

document.write ("Navigator.appversion value is" + navigator.appversion) for Navigator 2.0 running on Windows 95, the following information is displayed: Navigat The value of Or.appversion is 2.0 (Win95, I)

For Navigator 3.0 running on Windows NT, the following information is displayed: The value of Navigator.appversion is 3.0 (WinNT, I)

Example 2. The following example populates a Textarea object with a newline character separating each line of characters. Because the newline characters are different depending on the 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 line break will be set to \ r \ n, otherwise it will be set to \ n, 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= "first line" + newline + "second line" + newline + " Line 3 "} </SCRIPT> <form name=" Form1 "> <br><textarea name=" testlines "Rows=8 cols=55>< /textarea> <p><input type= "button" value= "Fill TEXTAREA Object" onclick= "Populate (Document.form1.testLines)" &   Gt </TEXTAREA> </FORM>

Language indicates the translated version of the Navigator being used.

Property source Navigator
Read-only
Implementation version Navigator 4.0

The value that describes language is typically two-letter code, such as "en", or in some cases a five-character code to indicate a language subtype, such as "ZH_CN".

Use this property to determine the language version of the Navigator that the customer uses, and you may want to display different translated text for users in different languages.

Mimetypes An array that contains all the supported MIME types for the client.

Property source Navigator
Read-only
Implementation version Navigator 3.0

The mimetypes array contains each MIME type supported by the client (in fact, this is implemented by a helper application or plug-in). For example, if a client supports three MIME types, these MIME types will be reflected in navigator.mimetypes[0], navigator.mimetypes[1], and navigator.mimetypes[2].

Each element of the mimetypes array is a MimeType object.

See MimeType

Platform indicates the type of machine Navigator compiled.

Property source Navigator
Read-only
Implementation version Navigator 4.0

The description platform values may be Win32, Win16, mac68k, MACPPC, and various Unix.

Depending on the version difference, emulator, or other reasons, the version compiled by the Navigator varies by machine type.

If you use SmartUpdate to download software to the user's machine, you can use this feature to ensure that the trigger downloads the corresponding JAR file. The trigger page will check the version of Navigator before checking the platform property. For more information about using SmartUpdate, see Use the JAR Installation manager for SmartUpdate.

Plugins contains an array of all the plugins currently installed by the client.

Property source Navigator
Read-only
Implementation version Navigator 3.0

Use this array to refer to the Plugin object installed by the client. Each element of the plugins array is a Plugin object. For example, if three plugins are installed on the client, these three plugins will be mapped to 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 that indicates the order in which the plug-in is installed by the client, or a string that contains the Plugin object name, which can be found in the name attribute. The first format returns the Plugin object stored in the specified position in the plugins array. The second format returns the MimeType object in the Plugin object.

To obtain the number of plug-ins installed by the client, you can use the Length property: Navigator.plugins.length.

Plugins.refresh: The plugins array has its own method, refresh. This method will make the newly installed plug-in available, update the related array, such as the plugins array, and optionally reload the open document that contains the plug-in. You can invoke the method using the following statement:

Navigator.plugins.refresh (True) Navigator.plugins.refresh (false) If you give true, refresh will make the newly installed plugin available, Reload all documents that contain embedded objects (EMBED tags). If you give false, the method will only flush the plugins array without re-loading any documents.

When the user installs the plug-in, the plug-in will not be available unless refresh is called, or the user shuts down and restarts the Navigator.

The following code refreshes the array and re-loads the document containing the embedded object:

Navigator.plugins.refresh (true) also see an example of the Plugin object.

UserAgent The string indicates the value of the HTTP Protocol user Agent header sent from the client to the server.

Property source Navigator
Read-only
Implementation version Navigator 2.0

Describes the server that uses the values sent in the user agent header to authenticate the customer.

The example below shows the useragent information in Navigator:

document.write ("Navigator.useragent value is" + navigator.useragent) for Navigator 2.0, the following is displayed:

The value of Navigator.useragent is mozilla/2.0 (Win16; I)

The javaenabled method tests whether Java is allowed.

method source Navigator
Static
Implementation version Navigator 3.0

The syntax javaenabled () parameter is none.

Description javaenabled Returns True if Java is allowed, otherwise false is returned. Users can enable or disable Java through parameter settings for user preferences.

The code below will execute function1 in case Java is allowed; otherwise function2.

if (navigator.javaenabled ()) {function1 ()} else function2 ()

See Navigator.appcodename, Navigator.appname, navigator.useragent

Preference allows the identified script to get and set preferences for some Navigator.

method source Navigator
Static
Implementation version Navigator 4.0

Syntax Preference (prefname) preference (prefname, setValue) parameters

Prefname Indicates the name of the preference item that you want to get or set. You can use the preferences listed below.
SetValue The value that you want to specify for the preference item. Can be a string, numeric, or Boolean value.

Describes this method to return the value of the preference item. If you use this method to set a value, the new value is returned.

Security use the Preference method to read preferences requires Universalpreferencesread permissions. Setting a preference with this method requires Universalpreferenceswrite permissions.

For more detailed information about the security in Navigator 4.0, see Chapter Seventh, "JavaScript security" in the JavaScript Guide.

With the permission, you can get and set preferences listed in table 8.2.

Table 8.2 Parameter Selection

... ... .
to do the following thingsset this parameterto give a
Allow or disallow automatic loading of images General.always_load_images True or False
Allow or disallow Java Security.enable_java True or False
Allow or disallow JavaScript Javascript.enabled True or False
Allow or disallow style sheets Browser.enable_style_sheets True or False
Allow or prohibit smartupdate Autoupdate.enabled True or False
Accept All Cookies Network.cookie.cookieBehavior 0
Only accept cookies sent back to the original server Network.cookie.cookieBehavior 1
Prohibit cookies Network.cookie.cookieBehavior 2
Warning before accepting cookies Network.cookie.warnAboutCookies True or False

taintenabled Specifies whether data stains are allowed.

method source Navigator
Static
Implementation version Navigator 3.0; deleted in Navigator 4.0

The syntax navigator.taintenabled () describes a stain that will prevent other scripts from passing confidential and private information, such as directory structure or user browsing history. JavaScript cannot send a tainted value to any server without an end-user license.

You can use taintenabled to decide whether to allow data stains. If data stains are allowed, taintenabled returns True, otherwise false is returned. The user can enable or disable the data stain ns_enable_taint the environment variable.

The code below will execute function1 in case the data stain is allowed; otherwise execute function2.

if (navigator.taintenabled ()) {function1 ()} else function2 ()

JavaScript's Navigator Object

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.