why is $(window).height() so wrong?

One possible reason may be that you are checking the console with firebug/ something else. So that you don't get window height correct due to firebug height.

You can try something like this:

take a span/div in you document:

<span id="res"></span>

and then

$(window).on('resize',function() { 
  $('#res').html("new height is: "+$(window).height()); 
});

Or if you want to check out put on firebug console then detach it from browser and then check the result.


For those who still has problem after above solutions...

Please check the view ratio of browser onto your project.html..

The value of $(window).height() is not as same as 'real' pixels of client area when the view ratio adjusted! (and so others $(xx).width()...in this situation)

(The browser remembered my careless 110% ratio adjusted days ago...)


I have seen jQuery's $(window).height() returning a wrong value on Chrome mobile, even though my viewport and DOCTYPE declarations were in place. Eventually I used window.innerHeight.


I was having the same problem in Firefox then I added <!DOCTYPE HTML> on my index and it worked.

Source: http://viralpatel.net/blogs/jquery-window-height-incorrect/

Tags:

Jquery