Created
October 21, 2011 08:28
-
-
Save Integralist/1303355 to your computer and use it in GitHub Desktop.
Analyze the viewport size with JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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