Resizing iframe height using javascript issue

Posted by Camran on Stack Overflow See other posts from Stack Overflow or by Camran
Published on 2010-04-17T17:33:45Z Indexed on 2010/04/17 18:03 UTC
Read the original article Hit count: 164

Filed under:
|
|
|
|

I have an iframe which content is a php-file, and that php-file displays some mysql records.

The more records, the larger the iframe height should get, otherwise it wont show all of the information in the iframe.

Here is a code I have for dynamically setting the iframe height, from the iframes content (the php file):

var x = document.body.scrollHeight;
x = x + 20 + 'px';
window.parent.document.getElementById("iframe001").style.height=x;

iframe001 is the iframe I am referring to above. I am adding 20px of height extra because of borders etc...

Now, sometimes this resizing works, sometimes it doesn't.

Does anybody know why it works sometimes. If I alert the 'x' variable, it shows different values sometimes, but most times it works.

Any other ways you know of setting the iframes height from the content of the iframe?

Thanks

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql