Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is the difference between height, scrollHeight and style.height

Status
Not open for further replies.

jadeite100

Programmer
May 17, 2006
19
CA
Hi:

I have a IFrame called "dataFrame". Does anybody know the difference between

document.getElementById('dataFrame').height

and

document.getElementById('dataFrame').Document.body.scrollHeight;

and

document.getElementById('dataFrame').style.height


function shrinkIFrame() {

var theFrame=document.getElementById('dataFrame');
var header,headerHeight,footer,navPrimaryMenu,navPrimaryMenuHeight,mainMenu2,iFrameHeight,mainMenu2Height,wholeWindowHeight;
var totalHeight,differenceHeight;

if(theFrame){

theFrame.style.display="block"
if(theFrame.Document && theFrame.Document.body.scrollHeight)
{


header=parent.document.getElementById('Header2');
navPrimaryMenu=parent.document.getElementById('navPrimaryMenu');
mainMenu2=parent.document.getElementById('mainMenu2');

headerHeight = header.offsetParent.offsetHeight;
navPrimaryMenuHeight=navPrimaryMenu.scrollHeight;
mainMenu2Height=mainMenu2.scrollHeight;
wholeWindowHeight=document.body.offsetHeight;
iFrameHeight =theFrame.Document.body.scrollHeight;

totalHeight =headerHeight+mainMenu2Height+navPrimaryMenuHeight;

differenceHeight = wholeWindowHeight - totalHeight;



//alert("differenceHeight: " + differenceHeight);

if (iFrameHeight > differenceHeight)
{
// 92 represent the row header, one row and the scrollbar
//alert("iFrameHeight > differenceHeight");
if (differenceHeight > 92)
{

theFrame.style.height=differenceHeight+ 'px';
}
else
{
alert("theFrame.height:"+theFrame.height+"theFrame.Document.body.scrollHeight:"+theFrame.Document.body.scrollHeight);
alert("differenceHeight:"+differenceHeight+"theFrame.style.height:"+theFrame.style.height);

theFrame.height=theFrame.Document.body.scrollHeight;

}

}
else
{

theFrame.style.height = differenceHeight +'px';
}


}
if(theFrame.attachEvent){

theFrame.detachEvent("onload", readjustIframe)
theFrame.attachEvent("onload", readjustIframe)
}
}

}
Yours,

Frustrated
 
style.height and .height will return the height of the visible window.

.scrollHeight will return the height of the visible + scrollable window

Nick
 
Hi:

Can you please tell me what is the
parent.document.getElementById('dataFrame').offsetHeight


Thanks.
 
offsetHeight gives you the amount of pixels offset
from the offsetParent
 
from what I can remember offsetHeight only works in IE.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top