使用easyXDM在父文档和从不同域(亚马逊)加载的子iframe之间进行通信 [英] Using easyXDM to communicate between parent document and child iframe loaded from a different domain (amazon)

查看:143
本文介绍了使用easyXDM在父文档和从不同域(亚马逊)加载的子iframe之间进行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用easyXDM在父文档和子iframe之间进行通信(从不同的域 - 亚马逊加载)。 iframe src是一个oauth签署的url,并有以下代码与加载它的父文档进行通信:

I'm trying to use easyXDM to communicate between parent document and child iframe (loaded from a different domain - amazon). The iframe src is an oauth signed url and has the following code to communicate with the parent document that loads it:

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.

在父级(hitch.html)中:

In parent (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);
    }
});

当我从父文档中加载amazonS3中的子iframe时,easyXDM正在子文件中创建另一个iframe iframe的src设置为http:// localhost:56789 / hitch.html?xdm_e = ...。这导致整个事情在一个循环中重复 - 父母再次尝试加载子iframe等。

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=..." . This causes the whole thing to be repeated in a cycle - with parent again trying to load the child iframe and so on.

我在Firefox 9.0上测试,它有postMessage支持。实际的消息正在正确发送,我可以看到消息框。除此之外,它还会在初始化easyXDM.socket时在父文档中引发url is undefined or empty错误,但它似乎不影响任何其他...

I'm testing on Firefox 9.0 which has postMessage support. 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...

谢谢,

推荐答案

我认为你只有逻辑反向。文档说得很清楚:

I think you've just got the logic backwards. The documentation says quite clearly:


当使用easyXDM时,首先加载消费者文档,然后让
easyXDM加载提供者。

"When using easyXDM you first load the consumer document and then let easyXDM load the provider."

consumer是父文档,easyxdm加载作为子iframe的provider。

The "consumer" is the parent document, and easyxdm loads the "provider" which is the child iframe.

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

这篇关于使用easyXDM在父文档和从不同域(亚马逊)加载的子iframe之间进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆