JavaScript DHTML/Javascript Objects/navigator

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

Application Code Name

   <source lang="html4strict">
 
   

<html> <head> <script language="JavaScript">

   function function1() {
      alert(navigator.appCodeName);
   }

</script> </head> <body> <input type="button" value="Browser Code Name" onClick="function1();"> </body> </html>



 </source>
   
  


Display all values in navigator object

   <source lang="html4strict">

<html> <head>

   <title>The navigator Object</title>
   <script type = "text/javascript" >
       function showProps() {
           var body = document.getElementsByTagName("body")[0];
           for (var prop in navigator) {
               var elem = document.createElement("p");
               var text = document.createTextNode(prop + ": " + navigator[prop]);
               elem.appendChild(text);
               body.appendChild(elem);
           }
       }
   </script>

</head> <body onload="showProps()"> </body> </html>

 </source>
   
  


Get application Minor Version (navigator.appMinorVersion)

   <source lang="html4strict">
 
   

<html> <head> <script language="JavaScript">

   function function1() {
       alert(navigator.appMinorVersion);
   }

</script> </head> <body>

   <input type="button" value="Minor Version" onClick="function1();">

</body> </html>



 </source>
   
  


Get application Name

   <source lang="html4strict">
 
   

<html> <head> <script language="JavaScript">

   function function1() {
       alert(navigator.appName);
   }

</script> </head> <body>

   <input type="button" value="Browser Name" onClick="function1();">

</body> </html>



 </source>
   
  


Get application name from navigator (navigator.appName)

   <source lang="html4strict">
 
   

<html> <head> <script language="JavaScript"> function function1() {

   var m = navigator.appName;
   alert("The name of your browser is "+"""+m+""");

} </script> </head> <body > <input type="button" value="Click here" onClick="function1();"> </body> </html>



 </source>
   
  


Get applicatoin Version

   <source lang="html4strict">
 
   

<html> <head> <script language="JavaScript">

   function function1() {
       alert(navigator.appVersion);
   }

</script> </head> <body>

   <input type="button" value="Version" onClick="function1()">

</body> </html>



 </source>
   
  


Get browser Language

   <source lang="html4strict">
 
   

<html> <body> <script language="JavaScript">

   var m = navigator.browserLanguage;
   alert("The language of your browser is "+"""+m+""")

</script> </body> </html>



 </source>
   
  


Get cpu Class

   <source lang="html4strict">
 
   

<html> <head> <script language="JavaScript"> function function1() {

   var m = navigator.cpuClass;
   if (m == "x86") {
       n = "Intel processor";
   } else if (m == "68K") {
       n = "Motorola processor";
   } else if (m == "Alpha") {
       n = "Digital processor"
   } else if (m == "PPC") {
       n = "Motorola processor";
   } else {
       n = "Unknown processor";
   }
   alert("The CPU of this machine is "+"""+m+""\n"+n); 

} </script> <body> <input type="button" value="Click here" onClick="function1();"> </body> </html>



 </source>
   
  


Get platform information

   <source lang="html4strict">
 
   

<html> <body> <script language="JavaScript">

   function function1() {
       alert(navigator.platform);
   } 

</script> <input type="button" value="Platform" onclick="function1();"> </body> </html>



 </source>
   
  


Get system Language from navigator (navigator.systemLanguage)

   <source lang="html4strict">
 
   

<html> <body> <input type="button"

      value="Check System Language"
      onclick="alert("Your system language code is: \n"+navigator.systemLanguage);">

</body> </html>



 </source>
   
  


Get the browser version through navigator.appVersion

   <source lang="html4strict">
 

<html> <head>

</head> <body> <script type="text/javascript"> document.write(parseFloat(navigator.appVersion)); document.close() </script> </body> </html>


 </source>
   
  


Get user Agent from navigator (navigator.userAgent)

   <source lang="html4strict">
 
   

<html> <body> <button onclick="alert(navigator.userAgent);">User Agent</button> </body> </html>



 </source>
   
  


Get user Language from navigator object (navigator.userLanguage)

   <source lang="html4strict">
 
   

<html> <body> <button onclick="alert(navigator.userLanguage);">User Language</button> </body> </html>



 </source>
   
  


Is Java enabled

   <source lang="html4strict">
 

<HTML> <HEAD> <SCRIPT language="JavaScript"> window.alert(navigator.appName + " "+navigator.platform); var hasJava= navigator.javaEnabled() if (hasJava==true)

 window.alert("Java enabled");

else

 window.alert("No Java");

</SCRIPT> </HEAD> <BODY> </BODY> </HTML>


 </source>
   
  


Is navigator taint Enabled (navigator.taintEnabled())

   <source lang="html4strict">
 
   

<html> <body> <script language="JavaScript"> function function1() {

   var flag = navigator.taintEnabled();
   if (flag == true) {
      alert("taintEnabled YES");
   } else {
      alert("taintEnabled NO");
   } 

} </script> <input type="button"

      value="Is data tainting in my browser enabled?" onClick="function1();">

</body> </html>



 </source>
   
  


Is onLine

   <source lang="html4strict">
 
   

<html> <body> <script language="JavaScript"> function function1() {

  var m = navigator.onLine;
  alert("The onLine value is: \n"+m); 

} </script> <input type="Button" value="Get the onLine value" onClick="function1();"> </body> </html>



 </source>
   
  


Language information from Navigator

   <source lang="html4strict">
 
   

<html> <body> <button onclick="alert(navigator.language);">Language</button> </body> </html>



 </source>
   
  


List all plugins

   <source lang="html4strict">
 

<html> <head>

</head> <body> <script type="text/javascript"> navigator.plugins.refresh(false); var numPlugins = navigator.plugins.length;

for (var i = 0; i < numPlugins; i++){

 var plugin = navigator.plugins[i];
 if (plugin) {
   document.write("" + plugin.name + "
") document.write(plugin.description); }

} </script> </body> </html>


 </source>
   
  


navigator.appCodeName

   <source lang="html4strict">
 

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

   <source lang="html4strict">
 

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

   <source lang="html4strict">
 

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

   <source lang="html4strict">
 

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

   <source lang="html4strict">
 

<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].description

   <source lang="html4strict">
 

<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="html4strict">
 

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

   <source lang="html4strict">
 

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

   <source lang="html4strict">
 

<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[3].description

   <source lang="html4strict">
 

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

   <source lang="html4strict">
 

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

   <source lang="html4strict">
 

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


Open Window based on user defined attributes

   <source lang="html4strict">
 

<html> <head>

 <script type="text/javascript">
   var newWindow
   function openWindow() {
     var winAtts = new String()
     winAtts = "";
     if(document.winOptions.toolbarOption.checked){winAtts += "toolbar,"}
     if(document.winOptions.menubarOption.checked){winAtts += "menubar,"}
     if(document.winOptions.scrollbarsOption.checked){winAtts += "scrollbars,"}
     if(document.winOptions.resizableOption.checked){winAtts += "resizable,"}
     if(document.winOptions.statusOption.checked){winAtts += "status,"}
     if(document.winOptions.locationOption. checked){winAtts += "location,"}
     if(document.winOptions.directoriesOption.checked){winAtts += "directories,"}
     if(document.winOptions.copyHistoryOption.checked){winAtts += "copyhistory,"}
     if(document.winOptions.customSizeOption.checked){
       winAtts += "height=" + document.winOptions.heightBox.value + ",";
       winAtts += "width=" + document.winOptions.widthBox.value + ",";
     }
     winAtts = winAtts.substring(0, winAtts.length-1);
     if (document.winOptions.pageType[1].checked){
       var urlVar = ""
       urlVar = document.winOptions.urlBox.value
       newWindow = window.open(urlVar,"newWindow",winAtts)
     }else{
       newWindow = window.open("","newWindow",winAtts)
newWindow.document.write("

Window Open Test

");
       newWindow.document.close();
     }
   }
    function closeWindow() {
      newWindow.close()
    }
 </script>

</head> <body> <form name="winOptions" method="post" action="null">

 <input type="radio" checked="checked" name="pageType" value="existing" />Existing Page
 <input type="radio" name="pageType" value="dynamic" /> Dynamic Page
 <input type="text" size="30" maxlength="256" name="urlBox" />
 <input type="checkbox" name="toolbarOption" /> Toolbar
 <input type="checkbox" name="menubarOption" /> Menubar
 <input type="checkbox" name="scrollbarsOption" /> Scrollbars
 <input type="checkbox" name="resizableOption" /> Resizable
 <input type="checkbox" name="statusOption" /> Status
 <input type="checkbox" name="locationOption" /> Location
 <input type="checkbox" name="directoriesOption" /> Directories
 <input type="checkbox" name="copyHistoryOption" /> Copy History
 <input type="checkbox" name="customSizeOption" /> Custom Size
 Width:
 <input type="text" size="5" maxlength="5" name="widthBox" />
 Height:
 <input type="text" size="5" maxlength="5" name="heightBox" />
 <input type="button" name="OpenButton" value="Open Window" onclick="openWindow()" />
 <input type="button" name="CloseButton" value="Close Window" onclick="closeWindow()" />

</form> </body> </html>


 </source>
   
  


Use userAgent to get the browser type

   <source lang="html4strict">
 

<html> <head>

</head> <body> <script type="text/javascript"> var browserType = navigator.userAgent.toLowerCase(); if(browserType.indexOf("mozilla")){

 document.write("Netscape Navigator");

}else if (browserType.indexOf("msie")){

 document.write("Microsoft Internet Explorer");

}else if (browserType.indexOf("opera")){

 document.write("Opera");

}else if (browserType.indexOf("webtv")){

 document.write("Web TV");

} document.close() </script> </body> </html>


 </source>