HTML/DOM:document.body.scrollHeight 的标准等效是什么?

5
近十年来,我一直在使用:
document.body.scrollHeight 

要返回浏览器窗口的“理想”高度。 当我强制 Internet Explorer 进入怪异模式时,这个方法运行良好,方法是使用怪异模式文档类型:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

现在我想选择标准模式,但是 scrollHeight的含义已经改变
  • 怪异模式document.body.scrollHeight = 文档的高度
  • 标准模式document.body.scrollHeight = <body>元素的高度

标准模式下等价于document.body.scrollHeight是什么?

另请参阅

1个回答

4

document.documentElement.scrollHeight 是我认为正确的。

对于现代浏览器,视口的高度是 window.innerHeight

如果以上内容不是您想要的,这里有一些其他选项:

  • document.documentElement.[scrollHeight,clientHeight,offsetHeight]
  • document.body.[scrollHeight,clientHeight,offsetHeight]
  • window.[inner,outer][Height,Width] ( 仅适用于现代浏览器 )

成功了,当IE在Win32应用程序中托管时,将代码document.body.getAttribute("scrollHeight", 0)更改为document.documentElement.getAttribute("scrollHeight", 0) - Ian Boyd

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接