By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,281 Members | 2,201 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,281 IT Pros & Developers. It's quick & easy.

resizing iframe does not work in Firefox...

P: n/a
sam
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.

Any help really appreciated.

Thanks,
Sam

Apr 12 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
sam wrote:
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.


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>

Apr 13 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.