HTML/DOM: What is standards equivalent of document.body.scrollHeight?

99封情书 提交于 2019-11-30 05:21:40

问题


For nearly a decade i've been using:

document.body.scrollHeight 

to return the "ideal" height of the browser window. This worked fine when i was forcing Internet Explorer into quirks mode, by using a quirks-mode doctype:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

Now i want to opt into standards mode, except the meaning of scrollHeight has changed:

  • Quirks Mode: document.body.scrollHeight = the height of the document
  • Standards Mode: document.body.scrollHeight = the height of the <body> element

What is the standards mode equivalent of document.body.scrollHeight?

See also

  • quirksmode.org: W3C DOM Compatibility - CSS Object Model View - ElementView properties
  • Using !DOCTYPE invalidates client height

回答1:


document.documentElement.scrollHeight I believe.

For viewport it's window.innerHeight for modern browsers.

If the above aren't what you want, here's a list of a bunch of them:

  • document.documentElement.[scrollHeight,clientHeight,offsetHeight]
  • document.body.[scrollHeight,clientHeight,offsetHeight]
  • window.[inner,outer][Height,Width] ( modern browsers only )


来源:https://stackoverflow.com/questions/3788830/html-dom-what-is-standards-equivalent-of-document-body-scrollheight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!