views:

1322

answers:

2

I am currently working on an existing site that uses iframes(sigh!), these are pretty painful to work with and I'm having problems getting the height of the iframe to scale with the height of the HTML content.

I've tried a few different script snippets that floats around on the interwebs, but none of them have worked for me. I really want to use jQuery to do this, but that's not an option because IT wants to keep the size of the pageload down.

Does anyone know of good way to do this, in a way that works on both FF and IE 6+?

+2  A: 

You should just be able to simply set the height and the width parameters - since these are both valid attributes of the iframe dom element.

function resize(width, height) {
  var frame = document.getElementById('my_iframe');
  frame.width = width;
  frame.height = height;
}

Of course, this only applies if you are attempting to resize the iframe from it's parent element (the document with the actual iframe tag). If you are trying to resize the iframe from within the iframe (the document the iframe loads) you will need to call a public function of the parent element to perform the resize.

In iframe: parent.resize(600, 800);

Michael Wales
Thanks for your reply :) I'm not sure if it solves my problem though. I'll elaborate:My problem is that I have an accordion with li-elements that expand and collapse, I want the height of the iframe to automatically change according to the height of the src-html that includes this accordion.
timkl
A: 

how do i invoke this, what do i put where?

Frank