Developers Web home

Retrieve the size of the browser Window

To retrieve the window size, we will write a function called:

getWindowSize()

We shall set it to return an array of two values, the width and the height:

function getWindowSize () {
theHeight = ( typeof( window.innerHeight ) == 'number' )?window.innerHeight:( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )?document.documentElement.clientHeight:document.body.clientHeight;
theWidth = ( typeof( window.innerWidth ) == 'number' )?window. innerWidth:( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )?document.documentElement.clientWidth:document.body. clientWidth;
return [ scrOfX, scrOfY ];
}
No conversation on this topic You must be logged in to add to the conversation