先看例子:
- <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>