Summary of several methods for determining browser types and IE versions using JS

Source: Internet
Author: User

Copy codeThe Code is as follows: var isIE = !! Window. ActiveXObject;
Var isIE6 = isIE &&! Window. XMLHttpRequest;
Var isIE8 = isIE &&!! Document.doc umentMode;
Var isIE7 = isIE &&! IsIE6 &&! IsIE8;
If (isIE ){
If (isIE6 ){
Alert ("ie6 ");
} Else if (isIE8 ){
Alert ("ie8 ");
} Else if (isIE7 ){
Alert ("ie7 ");
}
}

--------------------------------------------------------------------------------Copy codeThe Code is as follows: if (navigator. appName = "Microsoft Internet Explorer" & navigator. appVersion. match (/6./I) = "6 ."){
Alert ("IE 6 ");
}
Else if (navigator. appName = "Microsoft Internet Explorer" & navigator. appVersion. match (/7./I) = "7 ."){
Alert ("IE 7 ");
}
Else if (navigator. appName = "Microsoft Internet Explorer" & navigator. appVersion. match (/8./I) = "8 ."){
Alert ("IE 8 ");
}
Else if (navigator. appName = "Microsoft Internet Explorer" & navigator. appVersion. match (/9./I) = "9 ."){
Alert ("IE 9 ");
}

--------------------------------------------------------------------------------Copy codeThe Code is as follows: if (navigator. userAgent. indexOf ("Opera ")! =-1 ){
Alert ('Opera ');
}
Else if (navigator. userAgent. indexOf ("MSIE ")! =-1 ){
Alert ('Internet Explorer ');
}
Else if (navigator. userAgent. indexOf ("Firefox ")! =-1 ){
Alert ('Firefox ');
}
Else if (navigator. userAgent. indexOf ("Netscape ")! =-1 ){
Alert ('netscape ');
}
Else if (navigator. userAgent. indexOf ("Safari ")! =-1 ){
Alert ('safari ');
}
Else {
Alert ('unrecognized browser. ');
}

--------------------------------------------------------------------------------Copy codeThe Code is as follows: if (! + '\ V1 '&&! '1' [0]) {
Alert ("ie6 or ie7 ")
}

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.