Window dimensions including scrolling in JavaScript

Let's get the dimensions of the window considering the scrolled part. Unfortunately, there is no convenient way that works in all browsers. Following are working solutions. You don't have to go into them, just use them.

A height including scrolled part:

let scrollHeight = Math.max( document.body.scrollHeight, document.documentElement.scrollHeight, document.body.offsetHeight, document.documentElement.offsetHeight, document.body.clientHeight, document.documentElement.clientHeight ); console.log(scrollHeight);

A width including scrolled part:

let scrollWidth = Math.max( document.body.scrollWidth, document.documentElement.scrollWidth, document.body.offsetWidth, document.documentElement.offsetWidth, document.body.clientWidth, document.documentElement.clientWidth ); console.log(scrollWidth);

On button click, display the height considering the scrolled part.

On button click, display the width considering the scrolled part.

On button click, display the height of the part hidden under the scrolling.

enru