This is not originally mine, but also I don't know who originally wrote this. I use it to calulate heights, my widths are always 100% browser width. It calculates the browser's height and width. Hope that this helps:
Code:
viewport =
{
getIECanvas: function ()
{
var canv = null;
if (!window.opera && document.all && typeof document.body.clientWidth != "undefined")
{
var cm = document.compatMode && document.compatMode == "CSS1Compat";
canv = cm ? document.documentElement : document.body;
}
return canv;
},
getWinWidth: function ()
{
var canv;
if ( canv = this.getIECanvas() )
this.width = canv.clientWidth;
else
this.width = window.innerWidth - 18;
},
getWinHeight: function ()
{
var canv;
if (canv = this.getIECanvas())
this.height = canv.clientHeight;
else
this.height = window.innerHeight - 18;
},
getScrollX: function ()
{
var canv;
if (canv = this.getIECanvas())
this.scrollX = canv.scrollLeft;
else if (window.pageXOffset)
this.scrollX = window.pageXOffset;
else if (window.scrollX)
this.scrollX = window.scrollX;
else
this.scrollX = 0;
},
getScrollY: function ()
{
var canv;
if (canv = this.getIECanvas())
this.scrollY = canv.scrollTop;
else if (window.pageYOffset)
this.scrollY = window.pageYOffset;
else if (window.scrollY)
this.scrollY = window.scrollY;
else
this.scrollY = 0;
},
getAll: function ()
{
this.getWinWidth();
this.getWinHeight();
this.getScrollX();
this.getScrollY();
}
};
So you'd get something like:
Code:
viewport.getWinWidth();
object.style.width = (viewport.width-200) + "px";
Thanks,Erik.