Bleep Bleep In At The Bleep End

Tuesday, July 25, 2006
Javascript window properties

Javascript window properties:

If you need to test the inner width or height of a browser window so that you can set the dimensions of a page element on the fly you can use javascript like this...

var x,y;
if (self.innerHeight) // all except Explorer
{
x = self.innerWidth; y = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
{
x = document.documentElement.clientWidth; y = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
x = document.body.clientWidth; y = document.body.clientHeight;
}
But, note:

1. You will need to activate the correct layout mode to make this work in some browsers (eg. IE6)
2. You may want to build in an automatic page refresh to activate if the window is manually resized

Posted by d - 1:00 am - 0 Comments

Add a Comment