jquery Detection Browser Information Implementation method

Source: Internet
Author: User
$ (document). Ready (function () {
Target Firefox 2 and above
if ($.browser.mozilla && $.browser.version >= "1.8") {
Do something
}
Target Safari
if ($.browser.safari) {
Do something
}
Target Chrome
if ($.browser.chrome) {
Do something
}
Target Camino
if ($.browser.camino) {
Do something
}
Target Opera
if ($.browser.opera) {
Do something
}
Target IE6 and below
if ($.browser.msie && $.browser.version <= 6) {
Do something
}
Target anything above IE6
if ($.browser.msie && $.browser.version > 6) {
Do something
}
});

Using JS detection

is to use a feature property that uses a browser. For example, to detect whether the browser supports the getElementById method can be used

if (document.getElementById) {
The method exists.
} else {
Do something else
}


A jquery

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


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.