First of all, thanks to Øyvind Kinsey for his great work, who made the job so easier for cross domain messaging. Even though it remains quite complicated, you opened a wide way through it ;-)
So let me introduce to you the problem we are actually dealing with :
We have a client that won't let us host our scripts on his domain, and is therefore pushing us to use this brillant piece of code that is easyXDM. We already implemented an iframe there a while ago (fetching a page from our domain, and displaying it in the main section of the website) and are about to implement a second one which is a widget in the sidebar. As we are using user authentication and various actions in both iframes (main iframe and widget), we would like the 2 iframes to communicate with each other and be able to trigger js events one on the other.
Let me add that their domain is actually calling a script (js) from our domain as well, which is initializing the widget. So we can execute javascript on the main page as well, but we will do so as few as possible.
We have been trying many different ways to make the 2 iframes communicate and there are the most advanced (or close to the point) :
- Establishing 2 page<->iframe connections between the main page and both iframes
this is not the best solution ever as it was loading more script to the initial website (easyXDM, eventually JSON2, flash...) and more importantly, loaded iframes inside iframes which already contained iframes... a real mess, occasionnally freezing some browsers. Indeed not the best solution.
- Establishing a direct link between the 2 iframes (even if they are hosted on the same domain)
easyXDM recognize that they are on the same domain and uses appropriate method (SOP)
BUT the javascript actions occur in easyXDM's hidden generated iframe and not in the iframe displayed. If I trigger a document.createElement, it would be shown in the iframe displayed, but in the hidden easyxdm's one.
My guess is that they don't find each other, as they are both enclosed in a page hosted on another domain. Guess the browser can't do that, can it ?
I may add that we are just trying to establish any kind of communication as we are only dealing with basic actions. We tried implementing easyXDM.Rpc though, with all (un)success described above. We are currently thinking about more basic solutions (as window.hash communication) but can't be sure to get 100% cross-browser compatibility before trying and this is already taking a lot of time and effort, and we would prefer to go through a tested solution.
Would anyone have a brillant idea on how to make this work ? Or at least explain what went wrong... I have crawled the easyXDM documentation and the Third-Party Javascript book (still in its early edition but yet very interesting, more info : http://thirdpartyjs.com/)
Any feedback appreciated, I hope my English was fine and the explanation too. If anything sounds blurry, please ask.
The two iframes are on the same domain?
If so, then simply load the second iframe normally (no easyXDM) and use
`parent.frames[frameName]` to access the sibling frame from either one. You
can easily control the name by setting the channel property which will make
the window name deterministic.
If your doing anything onload, then you'll have to account for any of the
two iframes rendering after the other, so a retry strategy must be applied.
When you described that the actions were performed in the hidden iframe
this is because easyXDM is designed to create the window it's talking to -
it cannot be used to interface directly with preexisting windows, nor can
it create iframes in other windows.
On Wed, Jul 4, 2012 at 10:09 AM, kartsims <karts...@gmail.com> wrote:
> Hello everyone,
> First of all, thanks to Øyvind Kinsey for his great work, who made the
> job so easier for cross domain messaging. Even though it remains quite
> complicated, you opened a wide way through it ;-)
> So let me introduce to you the problem we are actually dealing with :
> We have a client that won't let us host our scripts on his domain, and is
> therefore pushing us to use this brillant piece of code that is easyXDM. We
> already implemented an iframe there a while ago (fetching a page from our
> domain, and displaying it in the main section of the website) and are about
> to implement a second one which is a widget in the sidebar. As we are using
> user authentication and various actions in both iframes (main iframe and
> widget), we would like the 2 iframes to communicate with each other and be
> able to trigger js events one on the other.
> Let me add that their domain is actually calling a script (js) from our
> domain as well, which is initializing the widget. So we can execute
> javascript on the main page as well, but we will do so as few as possible.
> We have been trying many different ways to make the 2 iframes communicate
> and there are the most advanced (or close to the point) :
> - Establishing 2 page<->iframe connections between the main page and both
> iframes
> this is not the best solution ever as it was loading more script to the
> initial website (easyXDM, eventually JSON2, flash...) and more importantly,
> loaded iframes inside iframes which already contained iframes... a real
> mess, occasionnally freezing some browsers. Indeed not the best solution.
> - Establishing a direct link between the 2 iframes (even if they are
> hosted on the same domain)
> easyXDM recognize that they are on the same domain and uses appropriate
> method (SOP)
> BUT the javascript actions occur in easyXDM's hidden generated iframe and
> not in the iframe displayed. If I trigger a document.createElement, it
> would be shown in the iframe displayed, but in the hidden easyxdm's one.
> My guess is that they don't find each other, as they are both enclosed in
> a page hosted on another domain. Guess the browser can't do that, can it ?
> I may add that we are just trying to establish any kind of communication
> as we are only dealing with basic actions. We tried implementing
> easyXDM.Rpc though, with all (un)success described above. We are currently
> thinking about more basic solutions (as window.hash communication) but
> can't be sure to get 100% cross-browser compatibility before trying and
> this is already taking a lot of time and effort, and we would prefer to go
> through a tested solution.
> Would anyone have a brillant idea on how to make this work ? Or at least
> explain what went wrong... I have crawled the easyXDM documentation and the
> Third-Party Javascript book (still in its early edition but yet very
> interesting, more info : http://thirdpartyjs.com/)
> Any feedback appreciated, I hope my English was fine and the explanation
> too. If anything sounds blurry, please ask.