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

JS实现浏览器菜单命令

JavaScript Date对象详解

JavaScript Array对象详解

IE浏览器下PNG相关功能

javascript中CheckBox全选终极方案

简单分析javascript面向对象与原型

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

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

常用参考资料(手册)下载或者链接

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

精品推荐
分类导航