Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Window.open从父窗口打开的两个同级窗口之间的通信_Javascript_Angular_Cross Browser_Broadcastreceiver_Window.open - Fatal编程技术网

Javascript 使用Window.open从父窗口打开的两个同级窗口之间的通信

Javascript 使用Window.open从父窗口打开的两个同级窗口之间的通信,javascript,angular,cross-browser,broadcastreceiver,window.open,Javascript,Angular,Cross Browser,Broadcastreceiver,Window.open,我在两个窗口之间的通信中遇到问题。我有一个窗口p,它是父窗口。我使用window.open('path',A)打开新的2个新窗口(A,B);和窗口。打开('path',B)。现在我需要在A和B之间进行沟通。请帮助沟通B/w A和B 我试过了,但没用 // In A component window.opener('A').postMessage(JSON.stringify(messageData), "*"); //In B component window.addEventListene

我在两个窗口之间的通信中遇到问题。我有一个窗口p,它是父窗口。我使用window.open('path',A)打开新的2个新窗口(A,B);和窗口。打开('path',B)。现在我需要在A和B之间进行沟通。请帮助沟通B/w A和B

我试过了,但没用

// In A component
window.opener('A').postMessage(JSON.stringify(messageData), "*"); 

//In B component
window.addEventListener("message", this.receiveMessage.bind(this), false);
// IN A component
window.open('','A').postMessage(JSON.stringify(messageData), "*");

// IN B component
window.addEventListener("message", this.receiveMessage.bind(this), false);
我也试过了,但没用

// In A component
window.opener('A').postMessage(JSON.stringify(messageData), "*"); 

//In B component
window.addEventListener("message", this.receiveMessage.bind(this), false);
// IN A component
window.open('','A').postMessage(JSON.stringify(messageData), "*");

// IN B component
window.addEventListener("message", this.receiveMessage.bind(this), false);

还有一个我使用的广播不起作用

您需要在所有窗口中都有
消息
侦听器。所有打开的窗口(此处A和B)都将
postMessage()
转到
窗口。opener
(此处P)。然后,P将每个收到的消息转发到所有打开的窗口,但该消息的源(源)除外

// In A component
window.opener('A').postMessage(JSON.stringify(messageData), "*"); 

//In B component
window.addEventListener("message", this.receiveMessage.bind(this), false);
// IN A component
window.open('','A').postMessage(JSON.stringify(messageData), "*");

// IN B component
window.addEventListener("message", this.receiveMessage.bind(this), false);
Parent.html

//REM:包含所有打开的窗口
常量openedWindows=[];
window.onload=函数(){
//REM:接收postMessage()的侦听器
window.addEventListener('message',函数(事件){
//雷:只写输出
document.body.appendChild(document.createTextNode(event.data));
//REM:将消息转发到所有打开的窗口,但不包括源窗口

对于(var i=0,j=openedWindows.length;i)这个问题的状态是什么?我通过postMessage解决了这个问题