How to get height of entire document with JavaScript?

前端 未结 13 1790
逝去的感伤
逝去的感伤 2020-11-22 06:01

Some documents I can\'t get the height of the document (to position something absolutely at the very bottom). Additionally, a padding-bottom on seems to do nothing on these

13条回答
  •  攒了一身酷
    2020-11-22 06:45

    This is a really old question, and thus, has many outdated answers. As of 2020 all major browsers have adhered to the standard.

    Answer for 2020:

    document.body.scrollHeight
    

    Edit: the above doesn't take margins on the tag into account. If your body has margins, use:

    document.documentElement.scrollHeight
    

提交回复
热议问题