Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Prototype-based javascript window dimensions (See related posts)

Usage:
var dim = Position.GetWindowSize();
dim[0] is the window width
dim[1] is the window height

window can be specified, useful if you work with frames..

Position.GetWindowSize = function(w) {
        w = w ? w : window;
        var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
        var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
        return [width, height]
}


Comments on this post

kylealanhale posts on Mar 30, 2007 at 07:04
This works a bit better:

Usage:
var dim = Position.GetWindowSize();
dim.width is the window width
dim.height is the window height

Position.GetWindowSize = function(w) {
        var width, height;
        w = w ? w : window;
        this.width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
        this.height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
        
        return this;
}
ctran posts on Aug 30, 2007 at 16:21
Position.getWindowSize = function(w) {
var width, height;
w = w ? w : window;
width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);

return { width: width, height: height };
}

You need to create an account or log in to post comments to this site.


Related Posts