JS判断浏览器之Navigator对象

 更新时间:2007年01月28日 00:00:00   作者:  
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需再刷新一下页面才能执行]

相关文章

  • 全面了解JS中的匿名函数

    全面了解JS中的匿名函数

    下面小编就为大家带来一篇全面了解JS中的匿名函数。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-06-06
  • js中window.open的参数及注意注意事项

    js中window.open的参数及注意注意事项

    下面小编就为大家带来一篇js中window.open的参数及注意注意事项。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-07-07
  • JS中处理时间之setUTCMinutes()方法的使用

    JS中处理时间之setUTCMinutes()方法的使用

    这篇文章主要介绍了JavaScript中处理时间之setUTCMinutes()方法的使用,是JavaScript入门学习中的基础知识,需要的朋友可以参考下
    2015-06-06
  • Web开发之JavaScript

    Web开发之JavaScript

    笔者认为web开发包括设计html,javascript,css,以及一种高级语言,比如c#,java等等
    2012-03-03
  • JS中构造函数的基本特性与优缺点

    JS中构造函数的基本特性与优缺点

    这篇文章介绍了JS中构造函数的基本特性与优缺点,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-06-06
  • JavaScript 学习历程和心得分享

    JavaScript 学习历程和心得分享

    在过去,JavaScript只是被用来做一些简单的网页效果,比如表单验证、浮动广告等,所以那时候JavaScript并没有受到重视。
    2010-12-12
  • JavaScript 中的事件教程

    JavaScript 中的事件教程

    JavaScript 中的事件教程...
    2007-04-04
  • js 操作select和option常用代码整理

    js 操作select和option常用代码整理

    使用js过程中难免会碰到操作select和option的状况,本人也是深有同感,于是搜集整理一些常用且使用的代码,可供大家分享
    2012-12-12
  • Knockout text绑定DOM的使用方法

    Knockout text绑定DOM的使用方法

    本文讲解Knockout text绑定到DOM元素上,使得该元素显示的文本值为你绑定的参数。该绑定在显示<span>或者<em>上非常有用,可以用在任何元素上
    2013-11-11
  • 简介JavaScript中fixed()方法的使用

    简介JavaScript中fixed()方法的使用

    这篇文章主要介绍了JavaScript中fixed()方法的使用,是JS入门学习中的基础知识,需要的朋友可以参考下
    2015-06-06

最新评论