Link to home
Start Free TrialLog in
Avatar of selagea
selagea

asked on

Resizing iframe height to fit page contents

hello,

is there a way (using javascript or another language), to get my <iframe height=""> to change dynamically as a new page is loaded in it?

I want the iframe height to change dynamically so that i don't have to use another set of scrollbars inside the iframe...

please check this website to see what i mean: http://69.194.150.152/calendar.asp

you can see that the calendar changes while the rest of the page remains the same size... for example, when you press the "view" button, the page changes, yet i want the iframe to be resized so that you don't get a large white space underneath.

----------------------HOW I THINK IT CAN BE DONE---------------------------
have a function on the calendar.asp that can change the height of the iframe (in javascript)

then for each page that is loaded in the iframe, it will contain an embedded variable that tells it the height, and calls the function calendar.asp to resize it...
------------------------------------------------------------------------------------

Can anyone provide me some code to do this?

thanks very much
Avatar of Sleepyhead_NO
Sleepyhead_NO

i was unable to load your page, but i think this will work for you:

in calender.asp:
<iframe name="myiframe" src="iframe.asp"></iframe>
<script type="text/javascript">
function ChangeIframeHeight(NewHeight)
{
    document.frames.myiframe.style.height = NewHeight;
}
</script>

in iframe.asp:
<body onload="parent.ChangeIframeHeight('400px');">
ASKER CERTIFIED SOLUTION
Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of selagea

ASKER

thanks you very much, it works perfectly, and is easy to install
Glad we could help.  Thanks for the A. :^)

Cd&
OOps! wait a minute! There is a problem to this code: Why does the iframe shrink down after browsing many pages?
What about iframed .html pages which contains autoexpanding/compressing menus?
Is there a way in the containing page to dynamically fit the height to the variable source page height?