jQuery documentation http://api.jquery.com/height/ says
// Returns height of browser viewport
$( window ).height();
// Returns height of HTML document
$( document ).height();
But I got the same value from both method. For example, (with html including overflowed div with height=about 3000px)
$( window ).height();
3588
$( document ).height();
3588
$("body").height();
3572
$("html").height();
3588
window.innerHeight;
667
It gave the same result both in Chrome and Firefox browser. (The value is slightly different because of different size of toolbar.)
What I expected for $( window ).height()
was "height of browser viewport" which is window.innerHeight = 667
. But it gave 3588
which is much bigger than I expected.
Did I understand something wrong? Does viewport mean something different?
Anyway, in Find the exact height and width of the viewport in a cross-browser way (no Prototype/jQuery) , the way to get the height and width of the viewport is explained. In this document, "the viewport" is what I think, but not the one explained in jQuery documentation.
===============================================
Lately editted:
It only gives the wrong answer 3588
when I open the offline html file in my computer. When I uploaded the html file to my blog, and tested it, it gives the expected correct answer 667
. Is there any differnce between openning an offline file (file://) and an online html file (http://) ?
Short version of my test html file.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div style="height:3500px; background:rgb(200,200,255)" id="result"></div>
<script>
$("#result").html("$(window).height():? "+$(window).height());
</script>
It gives still
$(window).height():? 3516
in offline only.