Iframe

From Null-pointer

Jump to: navigation, search

Resizing contents in iframes

iframe code

<iframe id="myFrame" frameborder="0" vspace="0" hspace="0" marginwidth="0"
 marginheight="0" width="100%" src="external.html" scrolling="no"
 style="overflow:visible"></iframe>

javscript code

function adjustIFrameSize(id)
{
  var myiframe = parent.document.getElementById( id );
    
  var pad = 5;   

   if (myiframe.contentDocument && myiframe.contentDocument.body.offsetHeight )
   {
     //W3C DOM syntax for NN 6
     var newH = myiframe.contentDocument.body.offsetHeight;
     myiframe.height = newH + pad;
   }
   else if (myiframe.Document && myiframe.Document.body.scrollHeight )
   {
     var newH = myiframe.Document.body.scrollHeight;
     
     myiframe.height = newH + pad ;
   }
}

Taken from page 134 of Dyanmic HTML: The definitive reference, 2nd edition

Personal tools