I need to the iframe to autoresize according to the hight of its content, is that possible?
I need to the iframe to autoresize according to the hight of its content, is that possible?
Last edited by bojomojo; 12-07-2008 at 09:43 AM.
This can be done with javascript:
Code:function resizeIframe(iframeID) { if(self==parent) return false; /* Checks that page is in iframe. */ else if(document.getElementById&&document.all) /* Sniffs for IE5+.*/ var FramePageHeight = framePage.scrollHeight + 10; /* framePage is the ID of the framed page's BODY tag. The added 10 pixels prevent an unnecessary scrollbar. */ parent.document.getElementById(iframeID).style.height=FramePageHeight; /* "iframeID" is the ID of the inline frame in the parent page. */ }Credit to marsyas.HTML Code:<body id="framePage" onload="resizeIframe('idTopFrame')">
E d d y P r o c a
I love Dropbox. Get it through my (girlfriend's) referral link and both you and I (her) get 250 MB extra! Thanks and you're welcome!
will this work if the src of the iframe is from another domain?
Yes, it will resize the iframe on your page according to how big the other page is.
it is not working, nothing differs
Can you please post a link to your site, or attach the code to the page and the iframe?
E d d y P r o c a
I love Dropbox. Get it through my (girlfriend's) referral link and both you and I (her) get 250 MB extra! Thanks and you're welcome!
Page:
Iframe:Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Test Iframe Page</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <iframe id="iframeID" src="http://domain.com/?group=testtemplate" width="100%"></iframe> </div> </body> </html>
Code:<html> <head> <script type="text/javascript"> function resizeIframe(iframeID) { if(self==parent) return false; /* Checks that page is in iframe. */ else if(document.getElementById&&document.all) /* Sniffs for IE5+.*/ var FramePageHeight = framePage.scrollHeight + 10; /* framePage is the ID of the framed page's BODY tag. The added 10 pixels prevent an unnecessary scrollbar. */ parent.document.getElementById(iframeID).style.height=FramePageHeight; /* "iframeID" is the ID of the inline frame in the parent page. */ } </script> </head> <body id="framePage" onload="resizeIframe('iframeID')" > Content Here </body> </html>
Might be this:
Code:<body id="framePage" onload="resizeIframe('iframeID')" >
E d d y P r o c a
I love Dropbox. Get it through my (girlfriend's) referral link and both you and I (her) get 250 MB extra! Thanks and you're welcome!
i fixed this before you reply, and still doesnt work.
Please look and make sure the JS is in the right page and the page onload is on the right one, i got confused which goes to the parent page and which to the framed page
Yeah same here. I think that the javascript code should be on the main page, not in the iframe. Try that and see what happens.
E d d y P r o c a
I love Dropbox. Get it through my (girlfriend's) referral link and both you and I (her) get 250 MB extra! Thanks and you're welcome!
Bookmarks