Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 26th, 2012  |  syntax: None  |  size: 1.09 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Is there any way to automatically resize an iframe if the size of the content inside changes?
  2. <html>
  3. <head>
  4. <script type="text/javascript"></span>
  5.     function autoIframe(frameId){
  6.         try{
  7.             frame = document.getElementById(frameId);
  8.             innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
  9.  
  10.             if (innerDoc == null){
  11.                             // Google Chrome
  12.                 frame.height = document.all[frameId].clientHeight + document.all[frameId].offsetHeight + document.all[frameId].offsetTop;
  13.             }
  14.                     else{
  15.                     objToResize = (frame.style) ? frame.style : frame;
  16.                     objToResize.height = innerDoc.body.scrollHeight + 18;
  17.                     }
  18.         }
  19.  
  20.         catch(err){
  21.                 alert('Err: ' + err.message);
  22.             window.status = err.message;
  23.         }
  24.     }
  25.     </script>
  26. </head>
  27. <body>
  28.     <iframe id="tree" name="tree" src="tree.html" onload="if (window.parent && window.parent.autoIframe) {window.parent.autoIframe('tree');}"></iframe>
  29. </body>
  30. </html>