Reputation:
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
Upvotes: 1
Views: 2653
Reputation: 376
You might have forgotten the doctype <!DOCTYPE html>
at the beginning of the page.
Upvotes: 11
Reputation: 2455
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.
Upvotes: 4
Reputation: 382092
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.
Upvotes: 5