IE浏览器提供总网页高度为"0"



我正在尝试使用javascript获得网页的总高度,如下所示

var pageHeight = (document.height !== undefined) ? document.height : document.body.offsetHeight;

在其他浏览器中工作得很好,但Internet explorer为它返回值'0'。为什么?

这应该在所有浏览器中都有效:

var pageHeight = Math.max(document.height, document.body.scrollHeight,
    document.body.offsetHeight);

不要忘记在加载文档后执行代码。

编辑:我让这个希望它的工作,但我没有办法测试它在所有的浏览器,我不是100%确定。它改编自jQuery的源代码

最新更新