homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Cross-domain IFrame resize
How to resize a iframe dinamically?

 8:33 pm on Feb 28, 2008 (gmt 0)

Hello, my first post at this Forum.
I am maintaining a site on which i want to put a very simple CMS.I have a file,that is inside a iframe on my main page,which is hosted on another host,witch supports PHP but i can't move the whole site there(a bit confusing line, sorry).I am using Dynamic Drive's IFrame IIS script, but the JavaScript security doesn't allow me to do that.I found a topic, saying i could use Flash and a another one suggesting fragment identifiers.I need to dynamically resize an iframe's height.Please help!




 11:53 pm on Mar 6, 2008 (gmt 0)

echo back to you to see if I understand the problem

SiteA has an iframe showing content from SiteB
You need a script on siteB to resize the iframe in which it's being shown.

Or, is it that you can't predict how big the content on SiteB is, and you'd like your iframe to resize itself to fit snugly around it?

Either way, information about B has to communicate with A. If the two pages A and B are in the same domain, then it's totally possible. If they're not... then tough luck. :(

This is a problem I have struggled with repeatedly with no resolution. I don't think it's possible though I'd like to be proven wrong.

What was the suggestion using fragment ids? There could be possiblities there I haven't explored... Can SiteB add a frag to the URL, and does that change the src attribute of the iframe it's in? hmmm I feel an experiment coming on


 9:06 am on Mar 7, 2008 (gmt 0)

Thank you for the quick reply. I found that tread here : [tagneto.blogspot.com ]
I was also interested on that thread but as i see it's not concentrated on resizing, but communication between different domain iframes. I will read the thread another several hundred times :) and see if i have an idea.

PS:Sorry if i have any mistakes, i'm Bulgarian.


 9:09 am on Mar 7, 2008 (gmt 0)

Sorry i forgot for the other question:)
Or, is it that you can't predict how big the content on SiteB is, and you'd like your iframe to resize itself to fit snugly around it?
Yes, that's what i want to do.I have access to both pages.The pages are on different domains.

 6:36 pm on Mar 9, 2008 (gmt 0)

OK this fragment technique sounds like it could have some real potential. I'll do some experiments some time tomorrow and report here what I find out. The holy grail is a page that, when loaded in an iframe on another domain, resizes the iframe to fit snugly around itself. Of course this requires cooperation from both domains, but it also requires communication.
the hypothetical scenario:

Site B (in the iframe), onload, measures its own size. then it changes its location.href from "http://www.siteb.com/page.htm" to "http://www.siteb.com/page.htm#height:300px"

Site A (the parent page) sees that change - how? - and changes the height of the iframe to 300px


 7:13 pm on Mar 9, 2008 (gmt 0)

I've tried it myself too (don't ask me why), but there's one big disadvantage: It will fill up the browser's history with garbage. Tried solving that by using location.replace, but that always cause the corresponding window to reload (always it seems, even if only the hash changes), and in the case of the parent window, it resulted in endless reloads...

You could determine the change in the url by hooking on the window's onfocus event handler (and calling targetWindow.focus()), or by simply using window.setInterval. I had troubles with the first, so I made it with the second, but could not find a way around the problem of junk history entries.

Actually you could bypass the whole problem of cross-domain security by using mod_rewrite with proxying enabled? You could eventually make SiteB look like as if it would be part of SiteA, they would be situated in the same domain - at least that's what the browser would see...


 7:45 pm on Mar 10, 2008 (gmt 0)

I had expected (hoped) that when I change the location property of the iframe page, the src property of the iframe would have the #fragment in it.

It does not. At least not in Firefox.

myiframe.src shows the URL of the inner page, but without the # fragment


 7:06 pm on Mar 18, 2008 (gmt 0)

Thank you for the answers.I am still interested and i will monitor this thread

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved