For some reason both document height and window height return the same value, so when subtracting window from document height it returns 0. Anyone know why this might be happening?
console.log($(window).height());
console.log($(document).height());
The above both return the document height
For some reason both document height and window height return the same value, so when subtracting window from document height it returns 0. Anyone know why this might be happening?
console.log($(window).height());
console.log($(document).height());
The above both return the document height
Share Improve this question edited Apr 21, 2013 at 13:09 Matthew Gatland 3241 gold badge3 silver badges13 bronze badges asked Aug 23, 2012 at 18:57 user1522379user1522379 1- possibly because they are the same? you'll need to add some more information about your issue.. – Jake Long Commented Aug 23, 2012 at 18:59
3 Answers
Reset to default 11You might have forgotten the doctype <!DOCTYPE html>
at the beginning of the page.
That's because your document fills the viewport (the zone accessible for displaying the document).
From the documentation :
$(window).height(); // returns height of browser viewport
$(document).height(); // returns height of HTML document
If you document is long enough to take more than one page, the second value may be greater than the first (at least if the document is inside an iframe, look at this demo). There can be other cases generating differences but I have none in mind now.
I had a similar issues that I was able to fix. I found that
$(window).height();
Was returning the entire height of the page in FF. Eventually I realized that I was outputting a debug phrase 'test' before any of the html of the page. IE before the Doc type.
Once this 'test' text was removed the view port height was return as expected.