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

W

wolfing1

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.
 
W

wolfing1

Ian said:
I haven't tried it, but can you use the size of the iframe's <body> element?
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.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top