Blog
0

Javascript function to get current window height and width. Works with most of the browsers.

// function to get the current width of the window
function getWidth(){
var x = 0;
if (self.innerHeight){
    x = self.innerWidth;
}else if (document.documentElement && document.documentElement.clientHeight){
    x = document.documentElement.clientWidth;
}else if (document.body){
    x = document.body.clientWidth;
}
return x;
}

// function to get the current height of the window
function getHeight(){
var y = 0;
if (self.innerHeight){
    y = self.innerHeight;
}else if (document.documentElement && document.documentElement.clientHeight){
    y = document.documentElement.clientHeight;
}else if (document.body){
    y = document.body.clientHeight;
}
return y;
}

N.B. Originally posted @ my personal blog

Post comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>