ie6之前的版本,窗口的可视大小body元素的大小。html标记是隐藏的。
而对于现代浏览器,窗口的可视大小是html元素的大小。html、body元素对应到javascript中分别为document.documentElement、document.body.
因此ie6以后的版本,ff,safari的可视宽度和高度为:
var windowWidth = document.documentElement.clientWidth || document.body.clientWidth; var windowHeight = document.documentElement.clientHeight || document.body.clientHeight;
opera则以body元素计算窗口的可视大小:
windowWidth = document.body.clientWidth; windowHeight = document.body.clientHeight;
因此,计算浏览器的可视大小应该表示为:
var windowWidth = document.documentElement.clientWidth || document.body.clientWidth; var windowHeight = document.documentElement.clientHeight || document.body.clientHeight; // 标准下,opera的窗口的可是高度为document.body.clientWidth if (window.opera) { windowWidth = document.body.clientWidth; windowHeight = document.body.clientHeight; }
转载于:https://www.cnblogs.com/wangxiang/archive/2008/08/01/1258298.html
