建議使用 IE 進行測試,因爲對 IE 以外的瀏覽器無法識別(經測試,IE 5 也是辨認不出來滴,不過我相信沒有哪個火星人還在用 IE5 吧?)
<title>無標題文檔</title>
<script language="javascript">
function c(){
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;
}());
alert(ie);
}
</script>
</head>
<body οnlοad="c()">
</body>
</html>