How to use:
$.browser. [' Browser keyword ']
Copy Code code as follows:
$ (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 look at the source of jquery:
Copy Code code as follows:
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 the regular to match useragent to determine the type and version of the browser.
What if we're going to judge whether the current browser is IE6?
$.browser.msie&& ($.browser.version = = "6.0") &&!$.support.style
Similarly jquery determines whether the browser is IE7
$.browser.msie&& ($.browser.version = = "7.0")
If backward compatibility is not considered, and you do not want to import jquery in order to determine the browser types
The easiest way to judge IE is
Copy Code code as follows:
if (document.all) {
Alert ("IE6")
}
$.browser is a regular expression to match the useragent to determine the browser version and kind of the. jquery1.3.2 version of the document has been declared Jquery.browser and jquery.browser.version recommended deprecated, you can use the Jquery.suppo RT to replace
But the current situation, jquery.support is not good, and is very difficult to use, we still honestly use $.browser to determine the browser type bar
If it is to determine the version of IE I still recommend the use of IE conditional expression to write JS
Copy Code code as follows:
<!--[If ie]>
<script type= "Text/javascript" >
Alert ("IE")
</script>
<! [endif]-->
<!--[if IE 6]>
<script type= "Text/javascript" >
Alert ("IE6")
</script>
<! [endif]-->
<!--[if IE 7]>
<script type= "Text/javascript" >
Alert ("IE7")
</script>
<! [endif]-->
This is more accurate than the way we manually judge IE versions by $.browser, and we don't have to remember the use of jquery browser.