[英]how to communicate data between parent and child window from different http domain?
[英]Using easyXDM to communicate between parent document and child iframe loaded from a different domain (amazon)
我正在嘗試使用easyXDM在父文檔和子iframe之間進行通信(從不同的域加載 - 亞馬遜)。 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!");
}
});
上面的代碼保存在文檔的頭部。
在父(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等等。
我正在測試具有postMessage支持的Firefox 9.0。 實際的消息正在正確發送,我可以看到消息框。 除此之外,在初始化easyXDM.socket時,它還會在父文檔中拋出“url is undefined or empty”錯誤,但它似乎不會影響其他任何內容......
謝謝,
我認為你只是倒退了邏輯。 文檔說得非常清楚:
“當使用easyXDM時,首先加載使用者文檔,然后讓easyXDM加載提供者。”
“consumer”是父文檔,easyxdm加載“提供者”,即子iframe。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.