The code is as follows |
Copy Code |
Rwebkit =/(WebKit) [/] ([w.] +)/,//webkit Ropera =/(opera) (?:. *version)? [ /] ([W.] +)/,//opera Rmsie =/(MSIE) ([w.] +)/,//ie Rmozilla =/(Mozilla) (?:. *? RV: ([w.] +))?/,//mozilla |
With useragent, we can see that chrome can be matched in the following ways, but as with Safari, it has
"Safari," we can put it in the Rwebkit. Match before
The code is as follows |
Copy Code |
rchrome=/(Chrome) [/] ([w.] +)/ |
Also Firefox can do this, put it in front of the Rmozilla to judge
The code is as follows |
Copy Code |
rfirefox=/(Firefox) [/] ([w.] +)/ Uamatch:function (UA) {//primarily the type and version of the browser being obtained UA = Ua.tolowercase ();//parameter is navigator.useragent. Convert to lowercase, and of course it can be declared in a regular match case-sensitive (such as/(WebKit) [/] ([w.] +)/i) var match = rwebkit.exec (UA) | | Ropera.exec (UA) | | Rmsie.exec (UA) | | Ua.indexof ("compatible") < 0 && rmozilla.exec (UA) | | [];//because of the use of exec to match, the result returned is a whole matching and response of the child matching, such as/(Chrome) [/] ([W.] +)/,match will return chrome/13.0.782.220,match[1] get chrome,match[2] get 13.0.782.220; return {Browser:match[1] | | "", Version:match[2] | | " 0 "}; } Uamatch is a method in jquery where you start calling and saving browser model browser and version Browsermatch = Jquery.uamatch (useragent);//Calling Uamatch and returning object return {browser: MATCH[1] | | "", Version:match[2] | | " 0 "}; if (Browsermatch.browser) { jquery.browser[Browsermatch.browser] = True;//chromesafarioperamsiemozilla |
, such as our
To perform a specific operation under Opera browser, you can use $.browser.opera to determine whether Opera browser
code is as follows |
copy code |
(true, False) JQuery.browser.version = browsermatch.version;//browser version } if (jQuery.browser.webkit) { JQuery.browser.safari = true;//because Safari is using the AppleWebKit engine, and because of the safari with Chrome, is doing additional processing } |