Body onload event running before page is fully loaded in editmode

Vote:
 

I have a problem with the onload event of the body tag.

When im in edit mode this script will run before the body has fully loaded.
The script is adjusting so that divs will be same height but when checking all the divs clientHeight it only returns 0 when im in editmode.

this is the code:

<body onload="adaptIndexDivs();">

function adaptIndexDivs()
{
var rightDiv = document.getElementById('mainStartRightColumnContainer');
var leftDiv = document.getElementById('mainStartLeftColumnContainer');
// min-height
var height = 362;
// find the highest div
if (leftDiv && leftDiv.clientHeight > height) height = leftDiv.clientHeight;
if (rightDiv && rightDiv.clientHeight > height) height = rightDiv.clientHeight;
// set new height
if (leftDiv) leftDiv.style.height = height + 'px';
if (rightDiv) rightDiv.style.height = height + 'px';
if (top.location != location)
{
document.body.style.paddingLeft = "0";
document.body.style.paddingRight = "0";
}
}

#23745
Sep 15, 2008 12:20
Vote:
 

Hi Andreas!

Brief answer: Use element.offsetHeight.

Here goes...

I don't think you have a problem with the onload being executed too early, it is usually the other way round since the onload waits for all content to be loaded (images, objects and such). Since you actually get the answer 0 the DOM is loaded because otherwise you would get a javascript error since you are accessing a property of an unknown object.

So I am pretty sure the problem lies in the use of clientHeight property. Try using offsetHeight instead, they are not the same but I think it will suit your purpose better.

Anyway, if I remember correctly I think the clientHeight property is a Microsoft invention (extension) that you can't be sure is supported by other browsers than IE (though it actually is supported by quite a few now). I also think the clientHeight property will return 0 in IE if you check the property on an element that doesn't have a height specified, either by class or style.

 

/Regards

Henrik Tengelin

EPiServer Development Team

#24216
Sep 27, 2008 11:42