Forum Moderators: open

Message Too Old, No Replies

iframe and auto resizing

         

diabolus

11:16 pm on Jun 14, 2003 (gmt 0)



Is there any way, without using scrollbars, to make an iframe window automatically resize itself according to its content?

A forum like this would be a good example of what would go in the iframe window - the height would always be changing... can it be done without scrollbars?

Thanks,
dv

tedster

6:01 am on Jun 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, diabolus.

I can think of one way using javascript, but it's pretty ugly.

Here's the rub. There's no way to know how much height the iframe document is going to need until it has been fully loaded and rendered. So you need to write the code for the iframe using document.write(), and initially set a default value for the height attribute.

Then, after it's loaded, you can read this object -- document.body.scrollheight. Then reload the parent page, feeding that number in as the height attribute of the iframe by using document.write().

Your visitor will see the entire page re-draw after it's already been rendered, but it may happen rather quickly.

If you do want to work with this approach, here's another thread [webmasterworld.com] that talks about some of the cross-browser and other issues involved.

And here's a report [webmasterworld.com] that someone had success with a similar approach.