jQuery API 返回首页目录 | jQuery API 中英文对照版
$.browser
$.browser

包含从navigator.userAgent属性中读取的用户代理标签(代理检测)。

有效的标签有:safari, opera, msie, mozilla 这个属性在DOM载入完成之前就可以访问,所以可以使用它来针对某个浏览器添加ready事件。

有的时候,对象检测可能不太可靠,这时就有必要使用浏览器检测。最好是两种方式都不用! 把浏览器和对象检测结合使用,可以得到相当可靠的结果。

返回值:Boolean

 

示例:

如果当前的用户代理是IE的某个版本就返回true。

$.browser.msie

示例:

只在safari浏览器中提示-"this is safari!"。

if($.browser.safari) { $( function() { alert("this is safari!"); } ); }

 
$.browser

Contains flags for the useragent, read from navigator.userAgent. Available flags are: safari, opera, msie, mozilla

This property is available before the DOM is ready, therefore you can use it to add ready events only for certain browsers.

There are situations where object detections is not reliable enough, in that cases it makes sense to use browser detection. Simply try to avoid both!

A combination of browser and object detection yields quite reliable results.

Return value: Boolean
Example:

Returns true if the current useragent is some version of microsoft's internet explorer

$.browser.msie

Example:

Alerts "this is safari!" only for safari browsers

 if($.browser.safari) { $( function() { alert("this is safari!"); } ); }  
相关链接
asp之家 | jQuery官方网站 | jQuery中文网 | 电子书作者网站 | 电子书作者blog