Resizing an iframe according to its contents


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <script language="JavaScript">
  2. <!--
  3. function calcHeight()
  4. {
  5. //find the height of the internal page
  6. var the_height=
  7. document.getElementById('the_iframe').contentWindow.
  8. document.body.scrollHeight;
  9.  
  10. //change the height of the iframe
  11. document.getElementById('the_iframe').height=
  12. the_height;
  13. }
  14. //-->
  15. </script>
  16.  
  17. and in the body create the iframe tag:
  18.  
  19. <iframe width="700" id="the_iframe"
  20. onLoad="calcHeight();"
  21. src="testing_page.shtml"
  22. scrolling="NO"
  23. frameborder="1"
  24. height="1">
  25. An iframe capable browser is
  26. required to view this web site.
  27. </iframe>

URL: http://guymal.com/mycode/iframe_size/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.