JavaScript DHTML/Javascript Objects/navigator
Содержание
- 1 Application Code Name
- 2 Display all values in navigator object
- 3 Get application Minor Version (navigator.appMinorVersion)
- 4 Get application Name
- 5 Get application name from navigator (navigator.appName)
- 6 Get applicatoin Version
- 7 Get browser Language
- 8 Get cpu Class
- 9 Get platform information
- 10 Get system Language from navigator (navigator.systemLanguage)
- 11 Get the browser version through navigator.appVersion
- 12 Get user Agent from navigator (navigator.userAgent)
- 13 Get user Language from navigator object (navigator.userLanguage)
- 14 Is Java enabled
- 15 Is navigator taint Enabled (navigator.taintEnabled())
- 16 Is onLine
- 17 Language information from Navigator
- 18 List all plugins
- 19 navigator.appCodeName
- 20 navigator.appMinorVersion
- 21 navigator.appName
- 22 navigator.appVersion
- 23 navigator.cookieEnabled
- 24 navigator.mimeTypes[1].description
- 25 navigator.mimeTypes[1].type
- 26 navigator.onLine
- 27 navigator.platform
- 28 navigator.plugins[3].description
- 29 navigator.userAgent
- 30 navigator.userLanguage
- 31 Open Window based on user defined attributes
- 32 Use userAgent to get the browser type
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>
<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>
<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>
<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>
<html>
<body>
<input type="button"
value="Check System Language"
onclick="alert("Your system language code is: \n"+navigator.systemLanguage);">
</body>
</html>
<html>
<head>
</head>
<body>
<script type="text/javascript">
document.write(parseFloat(navigator.appVersion));
document.close()
</script>
</body>
</html>
<html>
<body>
<button onclick="alert(navigator.userAgent);">User Agent</button>
</body>
</html>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>