先看例子:
<script type="text/javascript"> //可断定这个浏览器是IE 或非IE, 注意if 的判断条件, 如果这个浏览器对象的innerWidth返回值为true, 证明 //这个浏览器不是IE. if(window.innerWidth) { document.write("no IE inner: "+window.innerWidth+" x "+window.innerHeight); } else { document.write("IE:"+document.body.clientWidth+" x "+document.body.clientHeight); } </script>
如果用with 程序可简化为:
<script type="text/javascript"> if(window.innerWidth) { with(window) { document.write("no IE inner: "+innerWidth+" x "+innerHeight); } } else { with(document.body) { document.write("IE:"+clientWidth+" x "+clientHeight); } } </script>