Let's look at the source of jquery:
The code is as follows |
Copy Code |
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) }; |
Test usage
$.browser. [' Browser keyword ']
The code is as follows |
Copy Code |
$ (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!"); } |
If the above browser is not enough to judge, we can write by ourselves Oh, the method is also very simple to add your browser name to the jquery function.
If you want to judge IE6 we can do the following
The code is as follows |
Copy Code |
$.browser.msie&& ($.browser.version = = "6.0") &&!$.support.style |
Other if ie6,7,8,9,10 can operate this way I will not be introduced here.