无法在'DOMWindow'上执行'postMessage':提供的目标原点('..')与收件人窗口的原点('')不匹配

时间:2016-07-20 12:26:54

标签: javascript jquery

我有一个包含按钮的小应用程序(localhost:55777)窗口。我打开这个应用程序作为另一个应用程序(localhost:3214)的弹出窗口。

我希望弹出(托管在localhost:3214),点击上面的按钮(localhost:55777)。为此,我使用window.postMessage()并通过addListener处理消息事件。

完整的代码在这里:

申请1(发件人)http://localhost:55777

<button id="closeme" onclick="closeParent()">Close Parent</button>

JS:

function closeParent() {    

window.postMessage("closePopUp", "http://localhost:3214");


return false;

}

申请2(接收人):http://localhost:3214

JS:

 function receiveMessage(event) {
    if (event.data == 'close') {
        alert("Message received");
    }
}
addEventListener("message", receiveMessage, false);

现在接收方在调用postMessage时永远不会获得方法命中。得到错误:

  

无法在'DOMWindow'上执行'postMessage':提供的目标来源('http://localhost:3214')与收件人窗口的来源('http://localhost:55777')不匹配。

有人可以建议解决这个问题。我正在使用类型脚本的jquery。

0 个答案:

没有答案