Thanks, John. After much study of tutorials on heights and widths, plus much head banging, I finally came up with this script, which does the trick:
Code:
window.onload = adjustContent;
window.onresize = adjustContent;
// Be sure we're working under DOM.
var DHTML = (document.getElementById || document.all);
function adjustContent(){
if (!DHTML) return;
var oHeader = new getObj('FPheader');
var oContent = new getObj('FPcontent');
// Move the top of the content area for all browsers.
oContent.style.top = parseInt(oHeader.obj.offsetHeight,10) + 'px';
// For IE browsers (which don't recognize window.innerWidth/Height), we
// have to adjust the height of the content area or the scroll bar will
// extend below the window. We also need to adjust the width to keep
// the scroll bar in the right place.
if (!window.innerWidth){
var oWinSize = getWinSize();
oContent.style.overflow = 'auto';
oContent.style.height = oWinSize.height - parseInt(oHeader.obj.offsetHeight,10);
oContent.style.width = oWinSize.width; // Quirks mode
if (document.documentElement && document.documentElement.clientWidth){ // Standards mode
oContent.style.width = oWinSize.width - getExcessWidth(oContent);
}
}
}
// Create an object to reference a div element.
function getObj(name){
if (document.getElementById){
this.obj = document.getElementById(name);
this.style = document.getElementById(name).style;
}
else if (document.all){
this.obj = document.all[name];
this.style = document.all[name].style;
}
}
// Determine the height and width of the viewport.
function getWinSize(){
var iWidth = 0, iHeight = 0;
if (document.documentElement && document.documentElement.clientHeight){
iWidth = parseInt(document.documentElement.offsetWidth,10);
iHeight = parseInt(document.documentElement.offsetHeight,10);
}
else if (document.body){
iWidth = parseInt(document.body.offsetWidth,10);
iHeight = parseInt(document.body.offsetHeight,10);
}
return {width:iWidth, height:iHeight};
}
// Total up any border and padding applied to the right and left sides of the content division.
// These must be removed from the window offsetWidth to set the style.width for the content
// division in IE. Note that borders and padding *must* be specified in pixels for this to
// work properly.
function getExcessWidth(oContent){
var iExcess = 0;
if (window.getComputedStyle) {
iExcess = parseInt('0' + window.getComputedStyle(oContent.obj, null).getPropertyValue("padding-left"),10) +
parseInt('0' + window.getComputedStyle(oContent.obj, null).getPropertyValue("padding-right"),10) +
parseInt('0' + window.getComputedStyle(oContent.obj, null).getPropertyValue("border-left"),10) +
parseInt('0' + window.getComputedStyle(oContent.obj, null).getPropertyValue("border-right"),10);
}
else if (oContent.obj.currentStyle) {
iExcess = parseInt('0' + oContent.obj.currentStyle.paddingLeft,10) +
parseInt('0' + oContent.obj.currentStyle.paddingLeft,10) +
parseInt('0' + oContent.obj.currentStyle.borderLeft,10) +
parseInt('0' + oContent.obj.currentStyle.borderRight,10);
}
return (iExcess);
}
(Not quite as simple as the original, eh? But, things never are.)
I solved the 'px' problem by doing a parseInt on the header height before adding the 'px' back on. Now FF and IE7 are both happy.
The double-scrollbar problem in IE7 was handled by putting scroll="no" in the body tag to get rid of the main scrollbar, and then deducting any left/right border or padding from the offsetWidth. Unfortunately, that means I have to specify the padding in pixels instead of ems, since IE7 returns the original em units instead of converting them to pixels like the other browsers.
I also ended up needing another script from AListApart to detect font-size changes, so the content could resize properly in response to those as well as to window resizing.
But, it all works now, in all the browsers I've got. I sure have wasted a lot of time on what is really just a minor effect!
Bookmarks