Skip to content

Instantly share code, notes, and snippets.

@coolicer
Created March 15, 2012 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coolicer/2042636 to your computer and use it in GitHub Desktop.
Save coolicer/2042636 to your computer and use it in GitHub Desktop.
HTML : ie and NONEIE
<!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