Get page height in JS (Cross-Browser)

后端 未结 3 1522
温柔的废话
温柔的废话 2021-02-15 15:34

What is the best way to get the actual page (not window) height in JS that is cross-browser compatible?

I\'ve seen a few ways but they all return different values...

3条回答
  •  遇见更好的自我
    2021-02-15 16:32

    var width = window.innerWidth ||
                html.clientWidth  ||
                body.clientWidth  ||
                screen.availWidth;
    
    var height = window.innerHeight ||
                 html.clientHeight  ||
                 body.clientHeight  ||
                 screen.availHeight;
    

    Should be a nice & clean way to accomplish it.

提交回复
热议问题