By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,226 Members | 1,411 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,226 IT Pros & Developers. It's quick & easy.

HELP: Dynamically resizing iFrame

P: n/a
I really need some help - i have already pulled out 1/2 my hear and
the rest is following quickly.....

I am designing a page containing an iFrame, the contents of which are
selected dynamically by the user, and it needs to resize
correspondingly - both height and width. the width isn't a problem; it
is set from its parent object using width=100%, but the height is a
killer.

Basically the user selects a menu item and the src of the iFrame is
set to that choice, but each selection has a different height - and
the width of the iframe also changes depending on the width of the
menu to its left.

i have tried to set a dynamic expression in its style property:

style="height:expression(document.contentIFrame.wi ndow.contentTable.clientHeight)"

but this works erratically

i have tried writing a seperate function which resizes the iframe when
a new choice is made, but have found that the function sets the iframe
to the height of the PREVIOUS object displayed. i cannot seem to be
able to access the current object no matter how i do it?

function setSize() {

//contentIFrame.window.document.recalc(true);

contentIFrame.frames.frameElement.style.height =
contentIFrame.window.contentTable.clientHeight;

}
Any ideas

cheers

tim
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Is JavaScript an option? Try:

h = document.body.scrollHeight;
w = document.body.scrollWidth;
this.style.height = h + 20;
this.style.width = w + 20;

This might be slightly off, but I've done something similar to that in the past.
Jul 20 '05 #2

P: n/a
sp*******@marx7.org (Trent) wrote in message news:<22*************************@posting.google.c om>...
Is JavaScript an option? Try:

h = document.body.scrollHeight;
w = document.body.scrollWidth;
this.style.height = h + 20;
this.style.width = w + 20;

This might be slightly off, but I've done something similar to that in the past.


Mate your a ledgend!!
thought id send a reply to let you know how i solved the problem - the
scrollHeight didnt work directly (although it did access the correct
height), as the iFrame was still somehow caching the values of the
previous content element, or not updating them quickly enough.

BUT by calling a function to set the size of the iFrame after the
contents have been updated:

function setSize() {

contentIFrame.frames.frameElement.style.height =
contentIFrame.document.body.scrollHeight;

}

and then calling the function again in the onload event of the iFrame
the cached values (or how ever the problem is caused) are updated in
time for the second call.

Thanks
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.