I want to provide my visitors the ability to see images in high quality, is there any way I can detect the window size (or better yet, the viewport size - see green area) of the browser with Javascript?
Thank you all for the quick answers.
Alix Axel
2009-08-08 07:17:07
a non jQuery solution would be good
allyourcode
2009-12-12 23:18:53
+2
A:
If you aren't using jQuery, it gets ugly. Here's a snippet that should work on all new browsers. The behavior is different in Quirks mode and standards mode in IE. This takes care of it.
var elem = (document.compatMode === "CSS1Compat") ?
document.documentElement :
document.body;
var height = elem.clientHeight;
var width = elem.clientWidth;
Chetan Sastry
2009-08-08 06:20:10
Doesn't this give you the height of the page, not the viewport? That's what this page seems to indicate: https://developer.mozilla.org/en/DOM/element.clientHeight
allyourcode
2009-12-12 23:13:27
Doesn't work in IE - http://www.quirksmode.org/dom/w3c_cssom.html#windowview
Chetan Sastry
2009-08-08 07:11:19
Even though this doesn't work in IE +1 for diagram :D. For a question like this, it should be a crime not to have more of these.
allyourcode
2009-12-12 23:14:29