js获取IE版本,while代码很特别

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
  
    <title>百度地图的Hello, World</title>
    <style type="text/css">
        body, html, #allmap { width: 100%; height: 100%; overflow: hidden; margin: 0; }
    </style>
</head>
<body>

<script>
  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;

}());
document.write(ie);
</script>
</body>
</html>

 

posted @ 2013-10-18 15:50  正定聚  阅读(318)  评论(0编辑  收藏  举报