user1522379
user1522379

Reputation:

document and window height return the same value?

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

Answers (3)

user511564
user511564

Reputation: 376

You might have forgotten the doctype <!DOCTYPE html> at the beginning of the page.

Upvotes: 11

Shane
Shane

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

Denys S&#233;guret
Denys S&#233;guret

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

Related Questions