1

When using $ (document ) . height() to get the document height, an issue is present when developer tools are initially open.

The height will be too low, such that when developer tools are closed, the height returned by jQuery does not cover the full document height.

What can be done to work around this issue so that when developer tools are open and the document is opened, the height is correct?

webketje
  • 10,376
  • 3
  • 25
  • 54
Union find
  • 7,759
  • 13
  • 60
  • 111

3 Answers3

2

Appearently the document height is not what you want. Look for the whole body height instead:

$('body').prop('scrollHeight')

Another idea would be to move the dev tools into another window, but the document does change depending on whether the dev tools are opened or closed.

Alex
  • 9,911
  • 5
  • 33
  • 52
1

Here is the link why is $(window).height() so wrong? might you can look. try something like this,

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

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

Make sure DOCTYPE declaration in your HTML page, http://viralpatel.net/blogs/jquery-window-height-incorrect/, such as

<!DOCTYPE html>
Community
  • 1
  • 1
Lumi Lu
  • 3,289
  • 1
  • 11
  • 21
1

window.innerHeight is the property you're looking for.

For example, this code detects whether all the document content is in view; irrespective of whether Dev Tools is open:

var scrolled_to_all = false;

if($(document).height() <= window.innerHeight) {
    scrolled_to_all = true;
}
Danny Beckett
  • 20,529
  • 24
  • 107
  • 134