|Cross-domain IFrame resize|
How to resize a iframe dinamically?
Hello, my first post at this Forum.
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
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.
Sorry i forgot for the other question:)
Yes, that's what i want to do.I have access to both pages.The pages are on different domains.
|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? |
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
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...
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
Thank you for the answers.I am still interested and i will monitor this thread