JavaScript Cross Browser Window Size

Wouldn’t it be nice if there was one simple solution to find a simple property, like the size of the browser window? Too bad IE8 and below don’t like to play nice.

1
2
3
4
5
6
7
8
9
10
11
12
13
if (window.innerHeight) {
    // Firefox, Webkit
    iH = window.innerHeight;
    iW = window.innerWidth;
    console.log("Height: " + iH + "px Width: " + iW + "px");
} else {
    // Internet Explorer
    // clientWidth/Height is inner window size
    // (window width minus the scroll bar, menu etc)
    iW = document.documentElement.clientWidth;
    iH = document.documentElement.clientHeight;
    alert("Inner Height: " + iH + "px Inner Width:" + iW);
}