Internet explorer gives total webpage height as "0"

1k Views Asked by At

I am trying to get total height of webpage using javascript as follows

var pageHeight = (document.height !== undefined) ? document.height : document.body.offsetHeight;

works fine for me in other browsers but Internet explorer returns a value '0' for it. why?

1

There are 1 best solutions below

2
On

This should work in all browsers :

var pageHeight = Math.max(document.height, document.body.scrollHeight,
    document.body.offsetHeight);

Don't forget to execute the code after the document is loaded.

EDIT : I let this in hope it works but I have no way to test it in all browsers and I'm not 100% sure. It's adapted from jQuery's source.