I have a webpage with an IFrame in it. The content for the IFrame could change per page and with it size. I don't want scrollbar's inside the IFrame but rather for the whole page. To accomplish this I must resize the height of the IFrame (width = fixed). But I can't seem to accomplish this.
The links within the Iframe load the new content but I have to access the parent document to be able to resize the IFrame height. Anyone any idea how I can resize the iframe from within javascript in the IFrame.
I am able to resize the window now, although it still has some strange behaviour (in Firefox I get a scrollbar now and then and I often have large blank space under/within the IFrame)
window.resizeframe = function (iframeName){
var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
if (iframeEl) {
iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous
var x,y;
var test1 = document.body.scrollHeight;
var test2 = document.body.offsetHeight
if (test1 > test2) // all but Explorer Mac
{ y = document.frames[iframeName].document.body.scrollHeight;; }
else // Explorer Mac;
//would also work in Explorer 6 Strict, Mozilla and Safari
{ y = document.body.offsetHeight; }
var new_h = y;
iframeEl.style.height = new_h + "px";
}
}
Only it does not work in FF. It gives me a scrollbar within my IFrame, which I do not want. Any suggestions?
please note that I am still currently editing the code to try to get it to work
I don't quite understand why the size was reported as it was, but the changed code below was tested on a ripped copy of your site.
Chrome and IE were complaining of cross-domain access but it may have been the way I was testing it.
Just install it as before and remove any other resizer installed on any page.
You should use the Firefox error console to fix other script errors occurring on your site.
Bookmarks