JS to determine the browser type of running JSP page and version example _javascript tips

Source: Internet
Author: User
These two days to make a judgment of the browser type and version number of the business, record the relevant JS code:
Copy Code code as follows:

function Allinfo () {

var ua = navigator.useragent;
UA = Ua.tolowercase ();
var match =/(WebKit) [\/] ([\w.] +)/.exec (UA) | |
/(opera) (?:. *version)? [ \/] ([\w.] +)/.exec (UA) | |
/(MSIE) ([\w.] +)/.exec (UA) | |
!/compatible/.test (UA) &&/(Mozilla) (?:. *? RV: ([\w.] +))?/.exec (UA) | | [];

If you need to get the browser version number: match[2]

Switch (match[1]) {
Case "MSIE"://ie
if (parseint (match[2]) = = 6) {//ie6
Alert ("IE6");
Alert ("Temporarily does not support IE7.0 and the following version of browsers, please upgrade your browser version!") ");
document.getElementById ("hid"). Style.display = "None";
document.getElementById ("Show"). Style.display = "block";
document.getElementById ("Nosee_b"). Style.display = "None";
}
else if (parseint (match[2]) = = 7) {//ie7
Alert ("IE7");
document.getElementById ("hid"). Style.display = "None";
document.getElementById ("Show"). Style.display = "block";
}
else if (parseint (match[2]) = = 8) {//IE8
Alert ("IE8");
}
else if (parseint (match[2]) = = 9) {
Alert ("IE9");
document.getElementById ("hid"). Style.display = "None";
}
Break
Case "WebKit"://safari or Chrome
Alert ("Safari or Chrome");
document.getElementById ("Middle"). Style.display = "None";
Break
Case "Opera"://opera
Alert ("opera");
Break
Case "Mozilla"://firefox
Alert ("Firefox");
document.getElementById ("hid"). Style.display = "None";
Break
Default
Break
}
}
Related Article

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.