JavaScriptNavigator

JavaScriptNavigator 首页 / JavaScript入门教程 / JavaScriptNavigator

JavaScript Navigator对象用于浏览器检测。它可用于获取浏览器信息,例如appName,appCodeName,userAgent等。

Navigator对象是window属性,因此可以通过以下方式访问它:

window.navigator

要么,

navigator

Navigator 对象属性

Navigator对象的许多属性可返回浏览器的信息。

编号 属性 说明
1 appName 返回名称
2 appVersion 返回版本
3 appCodeName 返回代码名称
4 cookieEnabled 如果启用了cookie,则返回true,否则返回false
5 userAgent 返回用户代理
6 language 返回语言。仅Netscape和Firefox支持。
7 userLanguage 返回用户语言。仅IE支持。
8 plugins 返回插件。仅Netscape和Firefox支持。
9 systemLanguage 返回系统语言。仅IE支持。
10 mimeTypes[] 返回mime类型的数组。 Netsc支持仅限ape和Firefox。
11 platform 返回平台,例如Win32。
12 online 如果浏览器在线则返回true,否则返回false。

Navigator 对象方法

Navigator对象的方法如下。

编号 方法 说明
1 javaEnabled() 检查是否启用了Java。
2 taintEnabled() 检查是否启用了异味。从JavaScript 1.2开始不推荐使用。

navigator对象示例 :

<script>
document.writeln("<br/>navigator.appCodeName: "+navigator.appCodeName);
document.writeln("<br/>navigator.appName: "+navigator.appName);
document.writeln("<br/>navigator.appVersion: "+navigator.appVersion);
document.writeln("<br/>navigator.cookieEnabled: "+navigator.cookieEnabled);
document.writeln("<br/>navigator.language: "+navigator.language);
document.writeln("<br/>navigator.userAgent: "+navigator.userAgent);
document.writeln("<br/>navigator.platform: "+navigator.platform);
document.writeln("<br/>navigator.onLine: "+navigator.onLine);
</script>
输出
navigator.appCodeName: Mozilla 
navigator.appName: Netscape 
navigator.appVersion: 5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 
(KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36 
navigator.cookieEnabled: true 
navigator.language: en-US 
navigator.userAgent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 
(KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36 
navigator.platform: Win32 
navigator.onLine: true

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

教程推荐

AI 音视频创作入门课 -〔唐子轩〕

后端工程师的高阶面经 -〔邓明〕

人人都用得上的数字化思维课 -〔付晓岩〕

手把手教你玩音乐 -〔邓柯〕

Web安全攻防实战 -〔王昊天〕

Serverless入门课 -〔蒲松洋(秦粤)〕

黄勇的OKR实战笔记 -〔黄勇〕

玩转Git三剑客 -〔苏玲〕

人工智能基础课 -〔王天一〕

好记忆不如烂笔头。留下您的足迹吧 :)