Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy iFrame height from another iFrame at resize?

Status
Not open for further replies.

Twinster

Programmer
Aug 18, 2008
12
SE
Hey Guys!
I have fairly good skills in Javascript but there is one thing I just can't seem to crack. My problem is such...

I have two iFrames aligned beside each other. Both with dynamic content. However, there is one iFrame that is the one that gets most updated (height-wise) and that is the left iFrame.

I have tried to adjust the right iFrame to have the exact height that the left iFrame has when the left one gets it's content updated, but with no luck what so ever.

How can i resize the right iFrame to the same height as the left one gets when it's updated with new content and at?

Sooo... What I mean is: How can I make the right iFrame inherit the left iFrames height when the left iFrame is updated?

I am using this script to resize the iFrames when new content is loaded into them:

Let's call the iFrames:

Left One: "m1"
Right One: "m2"

<script language="JavaScript">
<!--
function autoResize(id){
var newheight;
var newwidth;

if(document.getElementById){
newheight=document.getElementById(id).contentWindow.document .body.scrollHeight;
newwidth=document.getElementById(id).contentWindow.document .body.scrollWidth;
}

document.getElementById(id).height= (newheight) + "px";
document.getElementById(id).width= (newwidth) + "px";
}
//-->
</script>



I am in a serious deadline trouble and would be so greatful for any quick and reliable solutions for this problem.

Thank you guys!
Regards,
Richard

 
Do both of your iframes reside in the same domain, and is that domain the same domain as the page they are loaded in?

If not, do you have any control whatsoever about the content that is loaded into those iframes?

As far as I know, you will only be able to do this if either of those conditions are true. Of course, I'm assuming (you don't actually say) that the left frame is always resized to the height of its content, rather than an arbitrary height.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I have full control over what's loaded into these iFrames (both left and right). One is a news area and the other one is for misc. announcements.

There are four individual iFrames on index.html, all with their own ID and Name.

I want to size the right ones height to fit the left one's at all times. So, if there is another news item added, the left one will automatically resize as it is now. But the right one stays and throws of the layout. I want that to follow the height of the left one.

I really appreciate your help!

/Richard
 
Perhaps I'm missing something here, then... surely if you're resizing the left iframe when its content changes, you can simply set the right iframe to the same height in the same way?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
That's exactly what I want to do. But I want it to do so as the left iFrame changes height. I don't want to do it manually. The content on the left iFrame is far more then what's in the right, making the right iFrame shorter then the left. I want the right iFrame to dynamically change height as the right iFrame changes height so they are equally high.

Am i making any sense at all? lol

/Richard
 
You've already said that you change the height of the left frame as its content is updated, so what I don't understand is why you cannot simply do the same for the right frame at the same time.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks for all your help! I resolved the matter through some other solution. However, now I have another thing lurking around I can't seem to solve...

I have made a new thread about it so please have look at it...

best,
Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top