当前位置: 首页 > 图文教程 > 网络编程 > Javascript > JS判断浏览器之Navigator对象

Javascript
站长推荐的用js实现的多浏览器支持的图片轮换展示效果ie,firefox
用js实现的十进制的颜色值转换成十六进制的代码
DHTML form validation
js资料toString 方法
js资料prototype 属性
js实现的网站首页随机公告随机公告
一个效果写的HashTable代码
用js实现的一个Flash滚动轮换显示图片代码生成器
关于javascript函数的几个话题
极致之美——百行代码实现全新智能语言
htm调用JS代码
斑马线效果代码
从新浪弄下来的全屏广告代码 与使用说明
用js实现预览待上传的本地图片
用javascript自动显示最后更新时间
表单提交时自动复制内容到剪贴板的js代码
用roll.js实现的图片自动滚动+鼠标触动的特效
一段js小代码,计算距春节还有多少天
js中设计一段程序,让它能够打印自己的方法收集藏
自动生成文章摘要的代码[JavaScript 版本]

Javascript 中的 JS判断浏览器之Navigator对象


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 124 ::
收藏到网摘: n/a

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 全选 提示:你可先修改部分代码,再按运行]

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 全选 提示:你可先修改部分代码,再按运行]