Navigator 对象
包含有关浏览器的信息
注意: 没有应用于 navigator 对象的公开标准,不过所有浏览器都支持该对象。
Navigator 对象属性
1. appCodeName
一个只读字符串,声明了浏览器的代码名
IE | firefox | safari | opera | |
---|---|---|---|---|
true | true | true | true | true |
`navigator.appCodeName`
document.write("浏览器代号: " + navigator.appCodeName);
2. appName
可返回浏览器的名称
IE | firefox | safari | opera | |
---|---|---|---|---|
true | true | true | true | true |
`navigator.appName`
document.write("浏览器名称: " + navigator.appName);
3.appVersion
可返回浏览器的平台和版本信息。该属性是一个只读的字符串
IE | firefox | safari | opera | |
---|---|---|---|---|
true | true | true | true | true |
`navigator.appVersion`
document.write("浏览器版本信息: " + navigator.appVersion);
4.cookieEnabled
返回一个布尔值,如果浏览器启用了 cookie,该属性值为 true。如果禁用了 cookie,则值为 false
IE | firefox | safari | opera | |
---|---|---|---|---|
true | true | true | true | true |
`navigator.cookieEnabled`
document.write("是否启用 Cookie: " + navigator.cookieEnabled);
5.platform
只读的字符串,声明了运行浏览器的操作系统和(或)硬件平台
IE | firefox | safari | opera | |
---|---|---|---|---|
true | true | true | true | true |
`navigator.platform`
document.write("硬件平台: " + navigator.platform);
6.userAgent
只读的字符串,声明了浏览器用于 HTTP 请求的用户代理头的值
IE | firefox | safari | opera | |
---|---|---|---|---|
true | true | true | true | true |
`navigator.userAgent`
document.write("用户代理: " + navigator.userAgent);
7. onLine
一个只读的布尔值,声明了系统是否处于脱机模式
注释:在 IE 4+ 中,用户可以在浏览器中选择脱机工作的状态。当脱机工作被选后,系统就进入了脱机状态,内容将从缓存进行读取。
navigator.onLine
document.write(navigator.onLine)
Navigator 对象方法
1. javaEnabled
返回一个布尔值,该值指示浏览器是否支持并启用了 Java。如果是,则返回 true,否则返回 false。
IE | firefox | safari | opera | |
---|---|---|---|---|
true | true | true | true | true |
navigator.javaEnabled()
document.write("启用Java: " + navigator.javaEnabled());
文档内容出自 W3cSchool和菜鸟教程,
如需查看更详细的有关内容 请登录 http://www.w3school.com.cn/ 和 http://www.runoob.com/