Get cross-browser document height in JS

This function will return any document’s height.

[ad name=”Adsense – text only”]

It’s been tested in IE, FF, Safari, Chrome and Opera. If the actual document’s body height is less than the viewport height then it will return the viewport height instead.

The Source:

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

Leave a comment

Your email address will not be published. Required fields are marked *