snippet library logo
in category
Javascript / Frames / Dynamic Iframe resizing
Snippet details
ID: 527
Viewed: 949
Added: 2004-06-15
Version: 1.0
View Demo

User Rated at:
Rate This:
Snippets in this catagory         
Show Printable Version
I have seen this asked in more forums so i thought I would post it here in case anybody wants it.

this allows the iframe to go as big as the content inside it will want. so it really makes the heightof the iframe the same size as the content it loads in it.

browsers: IE6+, Mozilla, Netscape 6+

General Details
Snippet uploaded by: snippet
Email : webmaster@snippetlibrary.com
Snippet By: Unknown

<!---Head--->
// add this to the page that loads "into" the iframe.

<script type="text/javascript">

function autofitIframe(id){
 if (!window.opera && !document.mimeType && document.all && document.getElementById){
 parent.document.getElementById(id).style.height=this.document.body.offsetHeight+"px";
 }
 else if(document.getElementById) {
 parent.document.getElementById(id).style.height=this.document.body.scrollHeight+"px"
 }
 } 
</script>

<!---Body--->


/// load this in the iframe page, the src of the iframe tag.
<body onload="autofitIframe('ifrm')" >

// in the parent file "calling" the iframe you need to make it have an id.
// add this to the parent html file.

<iframe name="ifrm" id="ifrm" src="test.htm" width="400" height="600" scrolling="no" frameborder="0">Sorry, your browser doesn't support iframes.</iframe>




No Reviews to show


Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Subject:

Reviewed By:

Write a review:





Terms of Conditions
Powered By
Avian Hosting
© 2005 snippetlibrary.com All Rights Reserved.