It’s possible to analyze the viewport size in JavaScript but it’s a little messy:
-
Most browsers support
window.innerWidth
andwindow.innerHeight
. -
But IE6, 7, 8 and 9 in quirks mode require
document.body.clientWidth
anddocument.body.clientHeight
. -
All the main browsers support
document.documentElement.clientWidth
anddocument.documentElement.clientHeight
but it’s inconsistent. Either the window or document dimensions will be returned depending on the browser and mode.