JS判断浏览器之Navigator对象

(编辑:jimmy 日期: 2024/10/8 浏览:2)

The Navigator Object
导航对象
The JavaScript Navigator object contains all information about the visitor's browser. We are going to look at two properties of the Navigator object:
JS导航对象包含所有有关访问这者浏览器的信息。我们将看看两个导航对象的产物:

appName -  holds the name of the browser
appName - 含浏览器的名称 
appVersion - holds, among other things, the version of the browser
appVersion - 浏览器版本 
Example
举例 

[Ctrl+A 全选 注:引入外部Js需再刷新一下页面才能执行]
The variable browser in the example above holds the name of the browser, i.e. "Netscape" or "Microsoft Internet Explorer".
上面例子中变量brower(浏览器)被赋加了浏览器的名称,网景或是IE(或其他)

The appVersion property in the example above returns a string that contains much more information than just the version number, but for now we are only interested in the version number. To pull the version number out of the string we are using a function called parseFloat(), which pulls the first thing that looks like a decimal number out of a string and returns it.
上面例子中的appVersion属性返回一串包含比版本号更多的信息字符,但现在我们只要版本号。要从字符串中提出版本号我们使用一个叫parseFloat()的函数来返回数字。

IMPORTANT! The version number is WRONG in IE 5.0 or later! Microsoft start the appVersion string with the numbers 4.0. in IE 5.0 and IE 6.0!!! Why did they do that??? However, JavaScript is the same in IE6, IE5 and IE4, so for most scripts it is ok.
(有关JS返回IE版本号的问题)

Example
举例
The script below displays a different alert, depending on the visitor's browser:
根据访问者的浏览器,(不同的浏览器)下面的脚本将显示不同的警示:


[Ctrl+A 全选 注:引入外部Js需再刷新一下页面才能执行]
一句话新闻
一文看懂荣耀MagicBook Pro 16
荣耀猎人回归!七大亮点看懂不只是轻薄本,更是游戏本的MagicBook Pro 16.
人们对于笔记本电脑有一个固有印象:要么轻薄但性能一般,要么性能强劲但笨重臃肿。然而,今年荣耀新推出的MagicBook Pro 16刷新了人们的认知——发布会上,荣耀宣布猎人游戏本正式回归,称其继承了荣耀 HUNTER 基因,并自信地为其打出“轻薄本,更是游戏本”的口号。
众所周知,寻求轻薄本的用户普遍更看重便携性、外观造型、静谧性和打字办公等用机体验,而寻求游戏本的用户则普遍更看重硬件配置、性能释放等硬核指标。把两个看似难以相干的产品融合到一起,我们不禁对它产生了强烈的好奇:作为代表荣耀猎人游戏本的跨界新物种,它究竟做了哪些平衡以兼顾不同人群的各类需求呢?