JS or CSS to identify IE version of several methods

Source: Internet
Author: User

JS or CSS tutorials to identify the IE version of several methods

Today, I have collected several kinds of code for the identification of IE version, the need for a friend to refer to.

var isie=!! Window. ActiveXObject;
var Isie6=isie&&!window. XMLHttpRequest;
var isie8=isie&&!! Document.documentmode;
var isie7=isie&&!isie6&&!isie8;
if (Isie) {
if (isIE6) {
Alert ("IE6");
}else if (isIE8) {
Alert ("IE8");
}else if (isIE7) {
Alert ("IE7");
}
}


--------------------------------------------------------------------------------

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


--------------------------------------------------------------------------------

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


--------------------------------------------------------------------------------

if (!+ ' v1 ' &&! ') 1 ' [0]) {
Alert ("
Then list some CSS methods

For style names
If only let IE6 see with *html. Head{color: #000;}
If only let IE7 see with *+html. Head{color: #000;}
If only let FF see with: Root body. Head{color: #000;}
If only let FF, IE8 see with Html>/**/body. Head{color: #000;}
If you just don't let IE6 see Using Html>body. Head{color: #000;} is not valid for IE 6
If you just don't let FF, IE8 see Using *body. Head{color: #000;} is not valid for FF, IE8

For specific properties
If only let IE6 see with _. Head{_color: #000;}
If only let IE7 see Using + and _ Combined method:. Head{+color: #f00;!; _color: #000;}

IE8 Official edition hack
9″ Example: "margin:0px auto9;" Here's "9″ can distinguish all IE8 and Firefox."
"*" IE6, IE7 can be identified. IE8, Firefox can't.
"_" IE6 can identify "_" IE7, IE8, Firefox can not.
Such as:
. A {color: #f00; color: #f609; +color: #00FF00; _color: #0000FF;}
From left to right respectively corresponds to FFIE8 IE7 IE6
————————————————-
CSS hack compatible table for each browser:
Ie6ie7ie8firefoxchromesafari!importantyy_y*yy*+y9yyyynth-of-type (1) YY
code example:
#test {
color:red; * * All browsers are supported/*
Color:red!important;/* Firefox, IE7 support * *
_color:red; /* IE6 Support * *
*color:red; * * IE6, IE7 support * *
*+color:red; /* IE7 Support * *
COLOR:RED9; * * IE6, IE7, IE8 support * *
color:red; /* IE8 Support * *
}
Body:nth-of-type (1) p{color:red}/* Chrome, Safari support * *

Overall Test code example:
. test{
color:#;
Color: #0000FF;
[Color: #00FF00;
*color: #FFFF00;
_color: #FF0000;
}

Other Notes:
1, if your page is IE7 compatible with no problem, do not want to modify the existing code, but also in the normal use of IE8, Microsoft claims that developers only need to be in the current compatible IE7 Web site to add a line of code to solve the problem, this code is as follows:

2, Body:nth-of-type (1) If this is written, means that the global lookup body, will correspond to the first.
3, there are other formulations, such as:
*html #test {} or *+html #test {}
4, *+html to IE7 hack must ensure that the top of the HTML has the following statement:

5, Order: Firefox, IE8, IE7, IE6 sequence.

Little knowledge: What is CSS hack?
Because of different browsers, such as IE6, IE7, IE8, Firefox, and so on, the interpretation of the CSS is not the same, so will result in the resulting page effect is not the same, we need the page effect.

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.