JavaScript Tutorial/Navigator/Navigator Object — различия между версиями

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

Текущая версия на 08:24, 26 мая 2010

Associative object arrays of Navigator

<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] + "<br>");
           
      }
      else {
         document.write(i + "<br>");
      }
   }
   return;
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT>
showProperties(window.navigator);
</SCRIPT>
</HTML>


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



<html>
    <head>
    <title> Example of the navigator object</title>
    </head>
    <body>
    <script language="JavaScript">
    <!--
       document.write(navigator.appName);
    -->
    </script>
    </body>
    </html>


navigator.appCodeName

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



<html>
    <head>
    <title> Example of the appCodeName property of the navigator object</title>
    </head>
    <body>
    <script language="JavaScript">
    <!--
       document.write(navigator.appCodeName);
    -->
    </script>
    </body>
    </html>


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).



<html>
    <head>
    <title> Example of the appVersion property of the navigator object</title>
    </head>
    <body>
    <script language="JavaScript">
    <!--
    document.write(navigator.appVersion);
    -->
    </script>
    </body>
    </html>


navigator.language

The language property determines what language the browser supports.

The return value is a string.



<html>
    <head>
    <title> Example of the language property of the navigator object</title>
    </head>
    <body>
    <script language="JavaScript">
    <!--
         document.write(navigator.language);
    -->
    </script>
    </body>
    </html>


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.



<html>
    <head>
    <title> Example of the mimetypes property of the navigator object</title>
    </head>
    <body>
    <script language="JavaScript">
    <!--
         document.write(navigator.mimeTypes.length);
    -->
    </script>
    </body>
    </html>


navigator.mimeTypes[1].description

<html>
<head>
<title>History</title>
</head>
<body>
<script type="text/javascript">
document.writeln("<h1>navigator object</h1>");
document.writeln("navigator.userAgent: " + navigator.userAgent + "<br />");
document.writeln("navigator.appName: " + navigator.appName + "<br />");
document.writeln("navigator.appCodeName: " + navigator.appCodeName + "<br />");
document.writeln("navigator.appVersion: " + navigator.appVersion + "<br />");
document.writeln("navigator.appMinorVersion: " + navigator.appMinorVersion + "<br />");
document.writeln("navigator.platform: " + navigator.platform + "<br />");
document.writeln("navigator.cookieEnabled: " + navigator.cookieEnabled + "<br />");
document.writeln("navigator.onLine: " + navigator.onLine + "<br />");
document.writeln("navigator.userLanguage: " + navigator.userLanguage + "<br />");
document.writeln("navigator.mimeTypes[1].description: " + navigator.mimeTypes[1].description + "<br />");
document.writeln("navigator.mimeTypes[1].type: " + navigator.mimeTypes[1].type + "<br />");
document.writeln("navigator.plugins[3].description: " + navigator.plugins[3].description + "<br />");
</script>
</body>
</html>


navigator.mimeTypes[1].type

<html>
<head>
<title>History</title>
</head>
<body>
<script type="text/javascript">
document.writeln("<h1>navigator object</h1>");
document.writeln("navigator.userAgent: " + navigator.userAgent + "<br />");
document.writeln("navigator.appName: " + navigator.appName + "<br />");
document.writeln("navigator.appCodeName: " + navigator.appCodeName + "<br />");
document.writeln("navigator.appVersion: " + navigator.appVersion + "<br />");
document.writeln("navigator.appMinorVersion: " + navigator.appMinorVersion + "<br />");
document.writeln("navigator.platform: " + navigator.platform + "<br />");
document.writeln("navigator.cookieEnabled: " + navigator.cookieEnabled + "<br />");
document.writeln("navigator.onLine: " + navigator.onLine + "<br />");
document.writeln("navigator.userLanguage: " + navigator.userLanguage + "<br />");
document.writeln("navigator.mimeTypes[1].description: " + navigator.mimeTypes[1].description + "<br />");
document.writeln("navigator.mimeTypes[1].type: " + navigator.mimeTypes[1].type + "<br />");
document.writeln("navigator.plugins[3].description: " + navigator.plugins[3].description + "<br />");
</script>
</body>
</html>


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.



<html>
    <head>
    <title> Example of the plugins property of the navigator object</title>
    </head>
    <body>
    <script language="JavaScript">
    <!--
    var plugLength = navigator.plugins.length
    for(i=0; i<plugLength; i++){
         document.write(navigator.plugins[i].name);
    }
    -->
    </script>
    </body>
    </html>


navigator.plugins[3].description

<html>
<head>
<title>History</title>
</head>
<body>
<script type="text/javascript">
document.writeln("<h1>navigator object</h1>");
document.writeln("navigator.userAgent: " + navigator.userAgent + "<br />");
document.writeln("navigator.appName: " + navigator.appName + "<br />");
document.writeln("navigator.appCodeName: " + navigator.appCodeName + "<br />");
document.writeln("navigator.appVersion: " + navigator.appVersion + "<br />");
document.writeln("navigator.appMinorVersion: " + navigator.appMinorVersion + "<br />");
document.writeln("navigator.platform: " + navigator.platform + "<br />");
document.writeln("navigator.cookieEnabled: " + navigator.cookieEnabled + "<br />");
document.writeln("navigator.onLine: " + navigator.onLine + "<br />");
document.writeln("navigator.userLanguage: " + navigator.userLanguage + "<br />");
document.writeln("navigator.mimeTypes[1].description: " + navigator.mimeTypes[1].description + "<br />");
document.writeln("navigator.mimeTypes[1].type: " + navigator.mimeTypes[1].type + "<br />");
document.writeln("navigator.plugins[3].description: " + navigator.plugins[3].description + "<br />");
</script>
</body>
</html>


navigator.plugins.refresh()

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



<html>
    <head>
    <title> Example of the plugins.refresh method of the navigator object</title>
    </head>
    <body>
    <script language="JavaScript">
    <!--
         document.write(navigator.platform);
    -->
    </script>
    </body>
    </html>


navigator.preference()

Syntax



navigator.preference(name)
    navigator.preference(name, value)


navigator.taintEnabled()

The taintEnabled() specifies whether data tainting is enabled.



<html>
    <head>
    <title> Example of the taintEnabled method of the navigator object</title>
    </head>
    <body>
    <script language="JavaScript">
    <!--
    if(navigator.taintEnabled()){
         document.write("Data tainting is enabled");
    } else{
         document.write("There is no data tainting");
    }
    -->
    </script>
    </body>
    </html>