Usage:
$.browser.['browser keyword']
$(function() {
if($.browser.msie) {
alert("this is msie");
}
else if($.browser. safari)
{
alert("this is safari!");
}
else if($.browser.mozilla)
{
alert("this is mozilla!" );
}
else if($.browser.opera) {
alert("this is opera");
}
else {
alert("i don't konw!");
}
Let’s take a look at the source code of jQuery:
var userAgent = navigator.userAgent.toLowerCase();
// Figure out what browser is being used
jQuery.browser = {
version: ( userAgent.match( /. (?:rv|it|ra|ie)[/: ]([d.] )/ ) || [])[1],
safari: /webkit/.test( userAgent ),
opera: /opera/.test( userAgent ),
msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
mozilla: /mozilla/.test ( userAgent ) && !/(compatible|webkit)/.test( userAgent )
};
jQuery uses regular rules to match userAgent to determine the type and version of the browser.
If we want to determine whether the current browser is IE6, how should we determine it?
$.browser.msie&&($.browser.version == "6.0")&&!$.support.style
Same as jQuery. Whether the browser is IE7
$.browser.msie&&($.browser.version == "7.0")
If you do not consider backward compatibility and do not want to import jQuery in order to determine each browser type
The easiest way to judge IE is
if(document.all ){
alert("IE6")
}
$.browser is a .jquery1.3.2 version of the document that uses regular expressions to match userAgent to determine the browser version and type. It has been stated that jquery.browser and jquery.browser.version are recommended to be deprecated and jquery.support can be used instead
However, judging from the current situation, jquery.support is not easy to use and is very difficult to use. We still Honestly use $.browser to determine the browser type
If it is to determine the version of IE, I still recommend using IE’s conditional expressions to write JS
This is more accurate than manually judging the IE version through $.browser, and there is no need to remember how to use jquery's browser.