JavaScript Tutorial/Navigator/Navigator Object

Материал из Web эксперт
Перейти к: навигация, поиск

Associative object arrays of Navigator

   <source lang="javascript">

<HTML> <HEAD>

  <TITLE>Associative object arrays</TITLE>

<SCRIPT> function showProperties (theObject){

  for (var i in theObject) {
     if (theObject[i] != null) {
         document.write(i + " : " + theObject[i] + "
"); } else { document.write(i + "
"); } } return;

} </SCRIPT> </HEAD> <BODY> <SCRIPT> showProperties(window.navigator); </SCRIPT> </HTML></source>


navigator

The navigator object is a built-in object that is used to obtain information related to the Navigator browser.

Properties and Methods of the navigator object

Property/Method Description appCodeName Represents the code name of the browser appName Refers to the official browser name appVersion Refers to the version information of the browser javaEnabled() Function that tests to see that Java is supported in the browser language Refers to the language of the browser mimeTypes Refers to an array of MimeType objects that contains all the MIME types that the browser supports platform A string representing the platform on which the browser is running plugins Refers to an array of Plugin objects that contains all the plug-ins installed in the browser plugins.refresh() Checks for any newly installed plug-ins preference() Allows reading and setting of various user preferences in the browser taintEnabled() Tests to see whether data-tainting is enabled userAgent String that represents the user-agent header



   <source lang="javascript">

<html>

   <head>
   <title> Example of the navigator object</title>
   </head>
   <body>
   <script language="JavaScript">
   
   </script>
   </body>
   </html></source>
   
  

navigator.appCodeName

The appCodeName property refers to the internal code name of the browser.



   <source lang="javascript">

<html>

   <head>
   <title> Example of the appCodeName property of the navigator object</title>
   </head>
   <body>
   <script language="JavaScript">
   
   </script>
   </body>
   </html></source>
   
  

navigator.appVersion

The appVersion property gets the browser version.

The returned property contains the browser version, platform on which the browser is running, and the country (either international or domestic).



   <source lang="javascript">

<html>

   <head>
   <title> Example of the appVersion property of the navigator object</title>
   </head>
   <body>
   <script language="JavaScript">
   
   </script>
   </body>
   </html></source>
   
  

navigator.language

The language property determines what language the browser supports.

The return value is a string.



   <source lang="javascript">

<html>

   <head>
   <title> Example of the language property of the navigator object</title>
   </head>
   <body>
   <script language="JavaScript">
   
   </script>
   </body>
   </html></source>
   
  

navigator.mimeTypes

The mimeTypes obtains a list of all the MIME types supported by the browser.

The returned object is an array containing all supported MIME types.



   <source lang="javascript">

<html>

   <head>
   <title> Example of the mimetypes property of the navigator object</title>
   </head>
   <body>
   <script language="JavaScript">
   
   </script>
   </body>
   </html></source>
   
  

navigator.mimeTypes[1].description

   <source lang="javascript">

<html> <head> <title>History</title> </head> <body> <script type="text/javascript">

document.writeln("

navigator object

");

document.writeln("navigator.userAgent: " + navigator.userAgent + "
"); document.writeln("navigator.appName: " + navigator.appName + "
"); document.writeln("navigator.appCodeName: " + navigator.appCodeName + "
"); document.writeln("navigator.appVersion: " + navigator.appVersion + "
"); document.writeln("navigator.appMinorVersion: " + navigator.appMinorVersion + "
"); document.writeln("navigator.platform: " + navigator.platform + "
"); document.writeln("navigator.cookieEnabled: " + navigator.cookieEnabled + "
"); document.writeln("navigator.onLine: " + navigator.onLine + "
"); document.writeln("navigator.userLanguage: " + navigator.userLanguage + "
"); document.writeln("navigator.mimeTypes[1].description: " + navigator.mimeTypes[1].description + "
"); document.writeln("navigator.mimeTypes[1].type: " + navigator.mimeTypes[1].type + "
"); document.writeln("navigator.plugins[3].description: " + navigator.plugins[3].description + "
"); </script> </body> </html></source>


navigator.mimeTypes[1].type

   <source lang="javascript">

<html> <head> <title>History</title> </head> <body> <script type="text/javascript">

document.writeln("

navigator object

");

document.writeln("navigator.userAgent: " + navigator.userAgent + "
"); document.writeln("navigator.appName: " + navigator.appName + "
"); document.writeln("navigator.appCodeName: " + navigator.appCodeName + "
"); document.writeln("navigator.appVersion: " + navigator.appVersion + "
"); document.writeln("navigator.appMinorVersion: " + navigator.appMinorVersion + "
"); document.writeln("navigator.platform: " + navigator.platform + "
"); document.writeln("navigator.cookieEnabled: " + navigator.cookieEnabled + "
"); document.writeln("navigator.onLine: " + navigator.onLine + "
"); document.writeln("navigator.userLanguage: " + navigator.userLanguage + "
"); document.writeln("navigator.mimeTypes[1].description: " + navigator.mimeTypes[1].description + "
"); document.writeln("navigator.mimeTypes[1].type: " + navigator.mimeTypes[1].type + "
"); document.writeln("navigator.plugins[3].description: " + navigator.plugins[3].description + "
"); </script> </body> </html></source>


navigator.plugins

The plugins property returns an array of the Plugins object representing all the plug-ins installed on a particular browser.

These can be accessed by the indexed num passed.



   <source lang="javascript">

<html>

   <head>
   <title> Example of the plugins property of the navigator object</title>
   </head>
   <body>
   <script language="JavaScript">
   
   </script>
   </body>
   </html></source>
   
  

navigator.plugins[3].description

   <source lang="javascript">

<html> <head> <title>History</title> </head> <body> <script type="text/javascript">

document.writeln("

navigator object

");

document.writeln("navigator.userAgent: " + navigator.userAgent + "
"); document.writeln("navigator.appName: " + navigator.appName + "
"); document.writeln("navigator.appCodeName: " + navigator.appCodeName + "
"); document.writeln("navigator.appVersion: " + navigator.appVersion + "
"); document.writeln("navigator.appMinorVersion: " + navigator.appMinorVersion + "
"); document.writeln("navigator.platform: " + navigator.platform + "
"); document.writeln("navigator.cookieEnabled: " + navigator.cookieEnabled + "
"); document.writeln("navigator.onLine: " + navigator.onLine + "
"); document.writeln("navigator.userLanguage: " + navigator.userLanguage + "
"); document.writeln("navigator.mimeTypes[1].description: " + navigator.mimeTypes[1].description + "
"); document.writeln("navigator.mimeTypes[1].type: " + navigator.mimeTypes[1].type + "
"); document.writeln("navigator.plugins[3].description: " + navigator.plugins[3].description + "
"); </script> </body> </html></source>


navigator.plugins.refresh()

The plugins.refresh() checks for any new plug-ins installed on the browser.



   <source lang="javascript">

<html>

   <head>
   <title> Example of the plugins.refresh method of the navigator object</title>
   </head>
   <body>
   <script language="JavaScript">
   
   </script>
   </body>
   </html></source>
   
  

navigator.preference()

Syntax



   <source lang="javascript">

navigator.preference(name)

   navigator.preference(name, value)</source>
   
  

navigator.taintEnabled()

The taintEnabled() specifies whether data tainting is enabled.



   <source lang="javascript">

<html>

   <head>
   <title> Example of the taintEnabled method of the navigator object</title>
   </head>
   <body>
   <script language="JavaScript">
   
   </script>
   </body>
   </html></source>