views:

130

answers:

1

I want to access the iframe my page is in and resize it. By the way I'm doing it in javascript.

It's something like parent and height or offsetHeight.

<iframe src="mypage.asp" height="400" width="400" ></iframe> 

And in mypage.asp I do sth similar like this:

var h = // new height;
parent.height = h; 

But it ain't all right? Somebody else who knows more?

+1  A: 

Try this if you want to resize the iframe from within the page that is loaded in your iframe. It seems to work locally at least:

function doIt() {
    var elem = window.parent.document.getElementById('myIframe'); // the id of your iframe of course
    elem.style.height = '40em';
}

I assume both the page and your iframe are yours and have the same "origin".

npup
the resizing is actually just elem.height or elem.width.
poo
I think the element's `height` attribute actually isn't supported (in xhtml at least). Will try too look up some confirmation on that. Anyway, I prefer to do the styling via CSS rules, so that's why I'm manipulating these.
npup
It is arguably under some circumstaces nicer to add a css-class to it instead of writing to the inline styles. I guess it depends on how "dynamic" one wants the height to be.
npup