JavaScript Window Navigator浏览器信息

JavaScript Window Navigator

window.navigator 对象包含有关访问者浏览器的信息。

实例


<html>
<body>
<div id="example">div>

<script>

txt = "

Browser CodeName: " + navigator.appCodeName + "

"
; txt+= "

Browser Name: " + navigator.appName + "

"
; txt+= "

Browser Version: " + navigator.appVersion + "

"
; txt+= "

Cookies Enabled: " + navigator.cookieEnabled + "

"
; txt+= "

Platform: " + navigator.platform + "

"
; txt+= "

User-agent header: " + navigator.userAgent + "

"
; txt+= "

User-agent language: " + navigator.systemLanguage + "

"
; document.getElementById("example").innerHTML=txt;
script> body> html>

警告:来自 navigator 对象的信息具有误导性,不应该被用于检测浏览器版本,这是因为:

  • navigator 数据可被浏览器使用者更改
  • 浏览器无法报告晚于浏览器发布的新操作系统
浏览器检测

由于 navigator 可误导浏览器检测,使用对象检测可用来嗅探不同的浏览器。

由于不同的浏览器支持不同的对象,您可以使用对象来检测浏览器。例如,由于只有 Opera 支持属性 “window.opera”,您可以据此识别出 Opera。

例子:if (window.opera) {…some action…}

你可能感兴趣的:(js模块,学习日记)