Ian Collins wrote:
> 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.