Jquery checks Information Code such as the browser version

Source: Internet
Author: User

Check the browser version information or browsers. We can determine the user's user-agent features. Next, I will only introduce the inspection of four mainstream browsers. other browsers can be automatically added.

Let's take a look at the user-agent of the following four mainstream browsers:

Safari (Windows edition)

... AppleWebKit/523.12.9 (KHTML, like Gecko) Version/3.0 Safari/523.12.9
Opera (Opera 9.2 on Windows XP)

Opera/9.24 (Windows NT 5.1; U; zh-cn)
Mozilla (Firefox 2.0.11 on Windows XP)

... Windows NT 5.1; zh-CN; rv: 1.8.1.11) Gecko/20071127 Firefox/2.0.0.11
Internet Explorer (7.0 on Windows XP)

Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)


Core code

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)
};

In this way, you can quickly obtain information about the browser by using the $. browser object attributes in jQuery. $. Browser object: jQuery. browser object

Example of viewing browser-related information

The Code is as follows: Copy code

<Div id = "tip"> </div>
<Script>
$ (Function (){
Var browserTip = "your browser name is :";
If ($. browser. msie) {// IE browser
BrowserTip + = "IE ";
}
If ($. browser. mozilla) {// Firefox
BrowserTip + = "Mozilla Firefox ";
}
BrowserTip + = "version:" + $. browser. version; // obtain the version number.
$ ("# Tip" ).html (browserTip );
})
</Script>

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.