The window.navigator
object contains information about the visitor's browser.
The window.navigator
object can be written without the window prefix.
Some examples:
navigator.cookieEnabled
navigator.appCodeName
navigator.platform
The cookieEnabled
property returns true if cookies are enabled, otherwise false:
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"cookiesEnabled is " + navigator.cookieEnabled;
</script>
Try it Yourself »
The appName
property returns the application name of the browser:
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"navigator.appName is " + navigator.appName;
</script>
Try it Yourself »
This property is removed (deprecated) in the latest web standard.
Most browsers (IE11, Chrome, Firefox, Safari) returns Netscape as appName.
The appCodeName
property returns the application code name of the browser:
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"navigator.appCodeName is " + navigator.appCodeName;
</script>
Try it Yourself »
This property is removed (deprecated) in the latest web standard.
Most browsers (IE11, Chrome, Firefox, Safari, Opera) returns Mozilla as appCodeName.
The product
property returns the product name of the browser engine:
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"navigator.product is " + navigator.product;
</script>
Try it Yourself »
This property is removed (deprecated) in the latest web standard.
Most browsers returns Gecko as product.
The appVersion
property returns version information about the browser:
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = navigator.appVersion;
</script>
Try it Yourself »
The userAgent
property returns the user-agent header sent by the browser to the server:
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = navigator.userAgent;
</script>
Try it Yourself »
The information from the navigator object can often be misleading.
The navigator object should not be used to detect browser versions because:
The platform
property returns the browser platform (operating system):
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = navigator.platform;
</script>
Try it Yourself »
The language
property returns the browser's language:
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = navigator.language;
</script>
Try it Yourself »
The onLine
property returns true if the browser is online:
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = navigator.onLine;
</script>
Try it Yourself »
The javaEnabled()
method returns true if Java is enabled:
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = navigator.javaEnabled();
</script>
Try it Yourself »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!