手机
当前位置:查字典教程网 >编程开发 >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对象】相关文章:

学习Javascript面向对象编程之封装

IE浏览器下PNG相关功能

获取对象

JavaScript Array对象详解

javascript中clipboardData对象用法

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

javascript中CheckBox全选终极方案

深入理解JavaScript中的对象

JavaScript中string对象

COOL而实用的动态效果

精品推荐
分类导航