简体   繁体   English

使用easyXDM在父文档和从不同域加载的子iframe之间进行通信(亚马逊)

[英]Using easyXDM to communicate between parent document and child iframe loaded from a different domain (amazon)

I'm trying to use easyXDM to communicate between parent document and child iframe (loaded from a different domain - amazon). 我正在尝试使用easyXDM在父文档和子iframe之间进行通信(从不同的域加载 - 亚马逊)。 The iframe src is an oauth signed url and has the following code to communicate with the parent document that loads it: iframe src是一个oeuth签名的URL,并具有以下代码与加载它的父文档进行通信:

socket = new easyXDM.Socket({
    remote: "http://localhost:56789/hitch.html", /* parent document */
    remoteHelper: "http://localhost:56789/easyXDM/name.html",
    onMessage: function(message, origin){
        alert("Received '" + message + "' from '" + origin + "'");
    },
    onReady: function() {
        socket.postMessage("Yay, it works!");
    }
});

the above code is kept in the head portion of the document. 上面的代码保存在文档的头部。

In parent (hitch.html): 在父(hitch.html)中:

var transport = new easyXDM.Socket(/** The configuration */{
    local: "/easyXDM/name.html",
    swf: "/easyXDM/easyxdm.swf",
    onMessage: function(message, origin){
       transport.postMessage("This is a message received from " + location);
    }
});

When I load the child iframe from amazonS3 inside the parent document, easyXDM is creating another iframe inside the child iframe with src set to "http://localhost:56789/hitch.html?xdm_e=..." . 当我从父文档中的amazonS3加载子iframe时,easyXDM在子iframe中创建另一个iframe,其中src设置为“http:// localhost:56789 / hitch.html?xdm_e = ...”。 This causes the whole thing to be repeated in a cycle - with parent again trying to load the child iframe and so on. 这导致整个事情在一个循环中重复 - 父母再次尝试加载子iframe等等。

I'm testing on Firefox 9.0 which has postMessage support. 我正在测试具有postMessage支持的Firefox 9.0。 The actual messages are being sent properly and I can see the message boxes. 实际的消息正在正确发送,我可以看到消息框。 Other than this, it also throws a "url is undefined or empty" error in parent document when initializing easyXDM.socket but it doesn't seem to affect anything else... 除此之外,在初始化easyXDM.socket时,它还会在父文档中抛出“url is undefined or empty”错误,但它似乎不会影响其他任何内容......

Thanks, 谢谢,

I think you've just got the logic backwards. 我认为你只是倒退了逻辑。 The documentation says quite clearly: 文档说得非常清楚:

"When using easyXDM you first load the consumer document and then let easyXDM load the provider." “当使用easyXDM时,首先加载使用者文档,然后让easyXDM加载提供者。”

The "consumer" is the parent document, and easyxdm loads the "provider" which is the child iframe. “consumer”是父文档,easyxdm加载“提供者”,即子iframe。

ref - https://github.com/oyvindkinsey/easyXDM ref - https://github.com/oyvindkinsey/easyXDM

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM