Results 1 to 2 of 2

Thread: Getting Height of Div Setting Height of iFrame

  1. #1
    Join Date
    Dec 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Getting Height of Div Setting Height of iFrame

    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:
    Code:
    	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.
    Code:
    	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?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,951
    Thanks
    43
    Thanked 3,195 Times in 3,157 Posts
    Blog Entries
    12

    Default

    Well, this works:

    Code:
    <!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:

    Code:
    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •