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

Possible to resize an Iframe to its content's height?

P: n/a
Maybe this doesn't make any sense, but is it possible to dynamically
resize an iframe to the height of its contained page? Something that
works in Opera/Firefox/IE.
I can resize it with a
document.getElementById("frameItems").style.height = "200px" for
example, but was wondering if I could access somehow the full size its
inner page would take... which might not make much sense but still who
knows.

Mar 23 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
wo******@gmail.com wrote:
Maybe this doesn't make any sense, but is it possible to dynamically
resize an iframe to the height of its contained page? Something that
works in Opera/Firefox/IE.
I can resize it with a
document.getElementById("frameItems").style.height = "200px" for
example, but was wondering if I could access somehow the full size its
inner page would take... which might not make much sense but still who
knows.

I haven't tried it, but can you use the size of the iframe's <body> element?

--
Ian Collins.
Mar 24 '06 #2

P: n/a

Ian Collins wrote:
wo******@gmail.com wrote:
Maybe this doesn't make any sense, but is it possible to dynamically
resize an iframe to the height of its contained page? Something that
works in Opera/Firefox/IE.
I can resize it with a
document.getElementById("frameItems").style.height = "200px" for
example, but was wondering if I could access somehow the full size its
inner page would take... which might not make much sense but still who
knows.

I haven't tried it, but can you use the size of the iframe's <body> element?

--
Ian Collins.

Made it work! What I did (copied from somewhere in the web):
In the "inner" page, an onload like this:
<body onload="parent.adjustIFrameSize(window);">

And in the actual page a js function like this:
function adjustIFrameSize(iframeWindow) {
if (iframeWindow.document.height) {
var iframeElement = document.getElementById ("frameItems");
iframeElement.style.height = iframeWindow.document.height + 'px';
iframeElement.style.width = iframeWindow.document.width + 'px';
} else if (document.all) {
var iframeElement = document.all["frameItems"];
if (iframeWindow.document.compatMode &&
iframeWindow.document.compatMode != 'BackCompat') {
iframeElement.style.height =
iframeWindow.document.documentElement.scrollHeight + 5 + 'px';
iframeElement.style.width =
iframeWindow.document.documentElement.scrollWidth + 5 + 'px';
} else {
iframeElement.style.height =
iframeWindow.document.body.scrollHeight + 5 + 'px';
iframeElement.style.width = iframeWindow.document.body.scrollWidth
+ 5 + 'px';
}
}
}

where frameItems is the name of the frame containing the page.
Tested in IE, Firefox and Opera and works in all of them so good enough
for me.

Mar 24 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.