Created
March 15, 2012 07:01
-
-
Save coolicer/2042636 to your computer and use it in GitHub Desktop.
HTML : ie and NONEIE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<!--[if lt IE 7 ]> <html dir="ltr" class="ie6"> <![endif]--> | |
<!--[if IE 7 ]> <html dir="ltr" class="ie7"> <![endif]--> | |
<!--[if IE 8 ]> <html dir="ltr" class="ie8"> <![endif]--> | |
<!--[if IE 9 ]> <html dir="ltr" class="ie9"> <![endif]--> | |
<!--[if (gt IE 9)|!(IE)]><!--> | |
<html dir="ltr"> | |
<!--<![endif]--> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
</head> | |
<body> | |
<!-- | |
这里头和尾两种方法都可以使用,一种是用条件注释,一种是通过判断ie版本。 | |
--> | |
<script type="text/javascript"> | |
var ie = (function(){ | |
var undef, | |
v = 3, | |
div = document.createElement('div'), | |
all = div.getElementsByTagName('i'); | |
while ( | |
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->', | |
all[0] | |
); | |
return v > 4 ? v : undef; | |
}()); | |
var html = document.documentElement || document.getElementsByTagName("html")[0]; | |
function addClassIE(name){ | |
html.className = name ; | |
} | |
ie === 6 ? addClassIE("ie6"): ie === 7 ? addClassIE("ie7"): ie === 8 ? addClassIE("ie8"): ie === 9 ? addClassIE("ie9") : ""; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment