Viewport generally refers to the space we have available in a browser window.
The viewport width and height can be found through the
const width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; const height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
The values for
height above will be the width and height of the usable area in the browser window.
Do note that this is a solution for targeting only modern browsers (nothing under IE8).
To target older browsers, we will have to alter how we access
const body = document.getElementsByTagName('body'); const x = window.innerWidth || document.documentElement.clientWidth || body.clientWidth; const y = window.innerHeight || document.documentElement.clientHeight || body.clientHeight;
Now you can solve your code error in less than a minute.