sam wrote:[color=blue]
> Hi all,
>
> Hope some expert can help me resolve this.
>
> I am using the following code to resize an iframe according to the
> content in it so that the iframe does not use its scroll bar and uses
> the parent window scroll bar. This code works perfectly fine in IE but
> not in Firefox.. The iframe does not resize according to the content.
>
> function resizeIframe(id)
> {
> frame = document.getElementById(id);
> innerDoc = (frame.contentDocument) ? frame.contentDocument :
> frame.contentWindow.document;
> objToResize = (frame.style) ? frame.style : frame;
>
> if ( IE)
> { objToResize.height = innerDoc.body.scrollHeight + 3; }
> else if (firefox)
> {
> objToResize.height = innerDoc.body.scrollHeight + 3;
> alert(innerDoc.body.scrollHeight);
> }
> }
>
> I noticed that (innerDoc.body.scrollHeight) works only when the iframe
> just keeps on expanding for various calls.. But say after 1 or 2 calls
> if the content is very little the iframe does not shrink back.[/color]
Hi, sorry I don't have time to fiddle with this, but here's a page
snippet that might give you some ideas. But this is something I'm sure
I've read about in this group many times over.
Csaba Gabor from Vienna
<iframe id=fred style="border:1px solid red;height:4in;width:2in"
src="data:text/html,<body style='border:1px solid green'>
tiny<br>little<br>iframe</body>"
onload="iframeLoaded()">
</iframe>
<script type='text/javascript'>
function elem(id) { return document.getElementById(id); }
function iframeLoaded() {
var idoc = elem('fred').contentDocument;
idoc.body.innerHTML = "awideriframethatshouldbeallononeline";
var more = "<br>qwer<br>poiu";
for (var i=10;i--;) idoc.body.innerHTML += more;
alert(idoc.defaultView.location.href);
// see
http://www.mozilla.org/docs/dom/domr...dow_ref76.html
idoc.defaultView.sizeToContent();
}
</script>