Here are two JavaScript functions you can use to get the height and width of the users browser.  I know you could do this with jQuery, or some other "Framework" or "Library", but why not just use what is in every browser.

The first function will return the currect width of the browser, and the second function will return the height. If the user changes the size of the browser you will need to call these functions again to get the new size.

//Get the width of an item
function GetWidth() {
    if (self.innerWidth) {
        return self.innerWidth;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        return document.documentElement.clientWidth;
    } else if (document.body) {
        return document.body.clientWidth;
    }
}

//Get the height of an item
function GetHeight() {
    if (self.innerHeight) {
        return self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        return document.documentElement.clientHeight;
    } else if (document.body) {
        return document.body.clientHeight;
    }
}

Categories


Most Visited