JavaScript DHTML/Javascript Objects/navigator — различия между версиями

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

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

Application Code Name

  
    
<html>
<head>
<script language="JavaScript">
    function function1() {
       alert(navigator.appCodeName);
    }
</script>
</head>
<body>
<input type="button" value="Browser Code Name" onClick="function1();">
</body>
</html>



Display all values in navigator object

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



Get application Minor Version (navigator.appMinorVersion)

  
    
<html>
<head>
<script language="JavaScript">
    function function1() {
        alert(navigator.appMinorVersion);
    }
</script>
</head>
<body>
    <input type="button" value="Minor Version" onClick="function1();">
</body>
</html>



Get application Name

  
    
<html>
<head>
<script language="JavaScript">
    function function1() {
        alert(navigator.appName);
    }
</script>
</head>
<body>
    <input type="button" value="Browser Name" onClick="function1();">
</body>
</html>



Get application name from navigator (navigator.appName)

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



Get applicatoin Version

  
    
<html>
<head>
<script language="JavaScript">
    function function1() {
        alert(navigator.appVersion);
    }
</script>
</head>
<body>
    <input type="button" value="Version" onClick="function1()">
</body>
</html>



Get browser Language

  
    
<html>
<body>
<script language="JavaScript">
    var m = navigator.browserLanguage;
    alert("The language of your browser is "+"""+m+""")
</script>
</body>
</html>



Get cpu Class

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



Get platform information

  
    
<html>
<body>
<script language="JavaScript">
    function function1() {
        alert(navigator.platform);
    } 
</script>
<input type="button" value="Platform" onclick="function1();">
</body>
</html>



Get system Language from navigator (navigator.systemLanguage)

  
    
<html>
<body>
<input type="button" 
       value="Check System Language"
       onclick="alert("Your system language code is: \n"+navigator.systemLanguage);">
</body>
</html>



Get the browser version through navigator.appVersion

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



Get user Agent from navigator (navigator.userAgent)

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



Get user Language from navigator object (navigator.userLanguage)

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



Is Java enabled

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



Is navigator taint Enabled (navigator.taintEnabled())

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



Is onLine

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



Language information from Navigator

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



List all plugins

  
<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("<b>" + plugin.name + "</b><br />")
    document.write(plugin.description);
  }
}
</script>
</body>
</html>



navigator.appCodeName

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

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

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

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

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

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

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

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

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



Open Window based on user defined attributes

  
<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("<h1>Window Open Test</h1>");
        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>



Use userAgent to get the browser type

  

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