手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >JS判断浏览器之Navigator对象
JS判断浏览器之Navigator对象
摘要:TheNavigatorObject导航对象TheJavaScriptNavigatorobjectcontainsallinformati...

TheNavigatorObject

导航对象

TheJavaScriptNavigatorobjectcontainsallinformationaboutthevisitor'sbrowser.WearegoingtolookattwopropertiesoftheNavigatorobject:

JS导航对象包含所有有关访问这者浏览器的信息。我们将看看两个导航对象的产物:

appName-holdsthenameofthebrowser

appName-含浏览器的名称

appVersion-holds,amongotherthings,theversionofthebrowser

appVersion-浏览器版本

Example

举例

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

Thevariablebrowserintheexampleaboveholdsthenameofthebrowser,i.e."Netscape"or"MicrosoftInternetExplorer".

上面例子中变量brower(浏览器)被赋加了浏览器的名称,网景或是IE(或其他)

TheappVersionpropertyintheexampleabovereturnsastringthatcontainsmuchmoreinformationthanjusttheversionnumber,butfornowweareonlyinterestedintheversionnumber.TopulltheversionnumberoutofthestringweareusingafunctioncalledparseFloat(),whichpullsthefirstthingthatlookslikeadecimalnumberoutofastringandreturnsit.

上面例子中的appVersion属性返回一串包含比版本号更多的信息字符,但现在我们只要版本号。要从字符串中提出版本号我们使用一个叫parseFloat()的函数来返回数字。

IMPORTANT!TheversionnumberisWRONGinIE5.0orlater!MicrosoftstarttheappVersionstringwiththenumbers4.0.inIE5.0andIE6.0!!!Whydidtheydothat???However,JavaScriptisthesameinIE6,IE5andIE4,soformostscriptsitisok.

(有关JS返回IE版本号的问题)

Example

举例

Thescriptbelowdisplaysadifferentalert,dependingonthevisitor'sbrowser:

根据访问者的浏览器,(不同的浏览器)下面的脚本将显示不同的警示:

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

【JS判断浏览器之Navigator对象】相关文章:

jQuery判断指定id的对象是否存在的方法

JavaScript实现单击下拉框选择直接跳转页面的方法

JavaScript的document和window对象详解

微信浏览器内置JavaScript对象WeixinJSBridge使用实例

判断checkbox选择的个数 多浏览器

JavaScript Date对象详解

深入浅析JavaScript面向对象和原型函数

javascript中clipboardData对象用法

深入理解JavaScript中的对象

js去除浏览器默认底图的方法

精品推荐
分类导航