resizing iframe does not work in Firefox...

S

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
 
C

Csaba Gabor

sam said:
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/domref/dom_window_ref76.html
idoc.defaultView.sizeToContent();
}
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top