Skip to content

Instantly share code, notes, and snippets.

@Integralist
Created October 21, 2011 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Integralist/1303355 to your computer and use it in GitHub Desktop.
Save Integralist/1303355 to your computer and use it in GitHub Desktop.
Analyze the viewport size with JavaScript
It’s possible to analyze the viewport size in JavaScript but it’s a little messy:
- Most browsers support `window.innerWidth` and `window.innerHeight`.
- But IE6, 7, 8 and 9 in quirks mode require `document.body.clientWidth` and `document.body.clientHeight`.
- All the main browsers support `document.documentElement.clientWidth` and `document.documentElement.clientHeight` but it’s inconsistent.
Either the window or document dimensions will be returned depending on the browser and mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment