.body.scrollHeight doesn't work in Firefox

后端 未结 2 1903
无人共我
无人共我 2020-12-10 15:06

.body.scrollHeight does not work in Firefox.

See: http://jsfiddle.net/gjrowe/X63KR/

What is the correct syntax to use instead?

相关标签:
2条回答
  • 2020-12-10 15:31

    This question has the same root problem as the thread at... Dynamically define iframe height based on window size (NOT CONTENT)

    Understanding the issue at that thread will give the solution to this.

    Basically, instead of using .body.scrollHeight, add this code...

    function getDocHeight() {
        var D = document;
        return Math.max(
            Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
            Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
            Math.max(D.body.clientHeight, D.documentElement.clientHeight)
        );
    }
    

    The answer was obtained from: http://james.padolsey.com/javascript/get-document-height-cross-browser/

    0 讨论(0)
  • 2020-12-10 15:31

    Use below code:

    JavascriptExecutor jse = (JavascriptExecutor) (WebDriverObject);
    jse.executeScript("window.scrollBy(0,document.body.scrollHeight || document.documentElement.scrollHeight)", "");
    
    0 讨论(0)
提交回复
热议问题