jquery Get user Browser version information

Source: Internet
Author: User
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
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.