How to get height of entire document with JavaScript?

前端 未结 13 1768
逝去的感伤
逝去的感伤 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:30

    You can even use this:

    var B = document.body,
        H = document.documentElement,
        height
    
    if (typeof document.height !== 'undefined') {
        height = document.height // For webkit browsers
    } else {
        height = Math.max( B.scrollHeight, B.offsetHeight,H.clientHeight, H.scrollHeight, H.offsetHeight );
    }
    

    or in a more jQuery way (since as you said jQuery doesn't lie) :)

    Math.max($(document).height(), $(window).height())
    

提交回复
热议问题