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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-06
  • 2021-10-17
  • 2021-12-19
  • 2022-12-23
  • 2021-05-24
猜你喜欢
  • 2021-12-31
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
  • 2021-06-09
相关资源
相似解决方案