PDA

View Full Version : Getting Height of Div Setting Height of iFrame



cgweaver
04-30-2006, 09:49 PM
I'm using the iFrame hack to cover some <select>s for the purpose of putting up a tooltip type message box. I would like to make the routines generic enough to work with a variety of boxes whose heights change dynamically to accomodate the amount of text they might contain.

I'm having trouble getting the height of the div with the message in it. I'm not wanting to set the height in css but would rather let it stretch out with the text. So the question is, how do I get the height value? I've tried this:

var divAV = document.getElementById('audiovisual');
var divWidth;
divWidth = divAV.style.width;
but I don't get a value in divWidth.

What's worse, the iFrame doesn't want to respond to dynamic changes to style.height.

var frameAV = document.getElementById('frame_audiovisual');
frameAV.style.height = "350px";
So it appears that even if I could get the height of the div I would be unable to set the height of the iFrame.

I'm trying to do this in an onload event handler so as to allow the document to load and the size of the divs to be set.

Anyone know how to do either or both of these things?

jscheuer1
05-01-2006, 08:31 AM
Well, this works:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
onload=function(){
document.getElementById('bob').style.height="350px";
}
</script>
</head>
<body>
<iframe id="bob" src="about:blank" width="100" height="100" scrolling="auto" frameborder="1"></iframe>
</body>
</html>

So, I'm not sure what the problem is with setting the iframe's height. To get the width of an element do this:


var fredWidth=document.getElementById('fred').offsetWidth

But, that won't get you anything useful unless the display property of 'fred' is not 'none' and 'fred' already contains the content and already possesses the styling it will have when you need to know its width.