Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.body.scrollHeight doesn't work in Firefox

Tags:

javascript

.body.scrollHeight does not work in Firefox.

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

What is the correct syntax to use instead?

like image 824
G-J Avatar asked Apr 10 '13 17:04

G-J


People also ask

How do you get the scrollHeight?

To get the height of the scroll bar the offsetHeight of div is subtracted from the clientHeight of div. OffsetHeight = Height of an element + Scrollbar Height. ClientHeight = Height of an element. Height of scrollbar = offsetHeight – clientHeight.

What is Document body scrollHeight?

The scrollHeight property returns the height of an element including padding, but excluding borders, scrollbars, or margins. The scrollHeight property returns the height in pixels.

How do I change the scroll height in jquery?

$(document). ready(function() { //Get height of the div var iHeight = $("#dvContent"). height(); //Get ScrollHeight of the div var iScrollHeight = $("#dvContent"). prop("scrollHeight"); var msg = 'Height:' + iHeight + 'px & ScrollHeight:' + iScrollHeight + 'px'; $("span").


2 Answers

Use below code:

JavascriptExecutor jse = (JavascriptExecutor) (WebDriverObject);
jse.executeScript("window.scrollBy(0,document.body.scrollHeight || document.documentElement.scrollHeight)", "");
like image 197
Ankit Gupta Avatar answered Sep 19 '22 12:09

Ankit Gupta


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/

like image 31
G-J Avatar answered Sep 19 '22 12:09

G-J