JavaScript Navigator



The window.navigator object contains information about the visitor's browser.


Window Navigator

window.navigator The object can be written without using the window prefix.

Instance

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文网(php.cn)</title>
</head>
<body>
	
<div id="example"></div>
<script>
txt = "<p>浏览器代号: " + navigator.appCodeName + "</p>";
txt+= "<p>浏览器名称: " + navigator.appName + "</p>";
txt+= "<p>浏览器版本: " + navigator.appVersion + "</p>";
txt+= "<p>启用Cookies: " + navigator.cookieEnabled + "</p>";
txt+= "<p>硬件平台: " + navigator.platform + "</p>";
txt+= "<p>用户代理: " + navigator.userAgent + "</p>";
txt+= "<p>用户代理语言: " + navigator.systemLanguage + "</p>";
document.getElementById("example").innerHTML=txt;
</script>

</body>
</html>

Run Instance»

Click the "Run Instance" button to view the online instance


WARNING!!!

The information from the navigator object is misleading and should not be used to detect browser versions because:

  • navigator data can be changed by the browser user

  • Some browsers will recognize the test site incorrectly

  • The browser cannot report that it is later than viewed New operating systems released by browsers


Browser detection

Since navigator can mislead browser detection, using object detection can be used to sniff different browsers.

Since different browsers support different objects, you can use objects to detect browsers. For example, you can identify Opera because only Opera supports the property "window.opera".

Example: if (window.opera) {...some action...}