471,602 Members | 1,305 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,602 software developers and data experts.

resizing iframe does not work in Firefox...

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
1 10433
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.

Similar topics

4 posts views Thread by khothikhe | last post: by
1 post views Thread by khothikhe | last post: by
5 posts views Thread by Paul Fi | last post: by
14 posts views Thread by Aaron Gray | last post: by
3 posts views Thread by PCgeek | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by CCCYYYY | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.