JavaScript Tutorial/Navigator/Navigator Object
Содержание
- 1 Associative object arrays of Navigator
- 2 navigator
- 3 navigator.appCodeName
- 4 navigator.appVersion
- 5 navigator.language
- 6 navigator.mimeTypes
- 7 navigator.mimeTypes[1].description
- 8 navigator.mimeTypes[1].type
- 9 navigator.plugins
- 10 navigator.plugins[3].description
- 11 navigator.plugins.refresh()
- 12 navigator.preference()
- 13 navigator.taintEnabled()
<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>
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>
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>
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>
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>
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>
<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>
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>
<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>
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>
Syntax
navigator.preference(name)
navigator.preference(name, value)
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>