Site icon ZoomingIn

Snippet – how to calculate the total height of the document with JavaScript

I needed for a project, I’m working on to calculate the total height of the document, not just the height of the visible view or of a particular element.

This is the script I got:

var B = document.body,
H = document.documentElement,
height

if(document.height !== undefined) {
height = document.height
} else {
height = Math.max( B.scrollHeight, B.offsetHeight,H.clientHeight, H.scrollHeight, H.offsetHeight );
}
Exit mobile version