This function will return any document’s height.

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)