JavaScript Window Navigator 浏览器本身的信息
JavaScript浏览器 信息 window navigator 本身
2023-09-14 09:00:18 时间
window.navigator 对象包含有关访问者浏览器的信息。
Window Navigator
window.navigator 对象在编写时可不使用 window 这个前缀。
Navigator Object Properties
Property | Description |
---|---|
appCodeName | Returns the code name of the browser |
appName | Returns the name of the browser |
appVersion | Returns the version information of the browser |
cookieEnabled | Determines whether cookies are enabled in the browser |
language | Returns the language of the browser |
onLine | Determines whether the browser is online |
platform | Returns for which platform the browser is compiled |
product | Returns the engine name of the browser |
userAgent | Returns the user-agent header sent by the browser to the server |
Navigator Object Methods
Method | Description |
---|---|
javaEnabled() | Specifies whether or not the browser has Java enabled |
taintEnabled() | Removed in JavaScript version 1.2. Specifies whether the browser has data tainting enabled |
实例:
<html> <body> <div id="example"></div> <script> txt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>"; txt+= "<p>Browser Name: " + navigator.appName + "</p>"; txt+= "<p>Browser Version: " + navigator.appVersion + "</p>"; txt+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>"; txt+= "<p>Platform: " + navigator.platform + "</p>"; txt+= "<p>User-agent header: " + navigator.userAgent + "</p>"; txt+= "<p>User-agent language: " + navigator.systemLanguage + "</p>"; document.getElementById("example").innerHTML=txt; </script> </body> </html>
警告:来自 navigator 对象的信息具有误导性,不应该被用于检测浏览器版本,这是因为:
- navigator 数据可被浏览器使用者更改
- 浏览器无法报告晚于浏览器发布的新操作系统
浏览器检测
由于 navigator 可误导浏览器检测,使用对象检测可用来嗅探不同的浏览器。
由于不同的浏览器支持不同的对象,您可以使用对象来检测浏览器。例如,由于只有 Opera 支持属性 "window.opera",您可以据此识别出 Opera。
例子:if (window.opera) {...some action...}
相关文章
- javascript_JavaScript走向成熟
- 【说站】javascript访问不同对象的速度比较
- 【说站】JavaScript中new函数的原理
- Javascript错误处理
- 多浏览器如何使用 javascript 获取页面、窗口详解编程语言
- JavaScript后门深层分析
- 21个值得收藏的Javascript技巧
- 浅谈javascript函数劫持[转自xfocus]
- javascript之更有效率的字符串替换
- javascript禁止复制网页
- Javascript阻止javascript事件冒泡,获取控件ID值
- 对象特征检测法判断浏览器对javascript对象的支持
- JavaScript让IE浏览器event对象符合W3CDOM标准
- javascript在事件监听方面的兼容性小结
- JavaScript在IE和Firefox浏览器下的7个差异兼容写法小结
- 让浏览器非阻塞加载javascript的几种方法小结
- 最短的javascript:地址栏载入脚本代码
- JavaScript快速检测浏览器对CSS3特性的支持情况
- 用Javascript来生成ftp脚本的小例子
- 不使用浏览器运行javascript代码的方法
- 浏览器的JavaScript引擎的识别方法
- javascript上传图片前预览图片兼容大多数浏览器
- JavaScript初学者建议:不要去管浏览器兼容
- javascript获取浏览器类型和版本的方法(js获取浏览器版本)
- JavaScript中一个奇葩的IE浏览器判断方法
- javascript的document.referrer浏览器支持、失效情况总结
- javascript实现浏览器窗口传递参数的方法