.body.scrollHeight在Firefox中不起作用

.body.scrollHeight doesn't work in Firefox

本文关键字:不起作用 Firefox scrollHeight body      更新时间:2023-09-26

.body.scrollHeight无法在Firefox中工作。

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

正确的语法是什么?

这个问题与线程在…根据窗口大小(NOT CONTENT)动态定义iframe高度

了解该线程的问题将给出解决方案。

基本上,不是使用.body.scrollHeight,而是添加以下代码…

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)
    );
}

答案来自:http://james.padolsey.com/javascript/get-document-height-cross-browser/

使用下面的代码:

JavascriptExecutor jse = (JavascriptExecutor) (WebDriverObject);
jse.executeScript("window.scrollBy(0,document.body.scrollHeight || document.documentElement.scrollHeight)", "");