如何将事件从父窗口发送到其子窗口?
问题描述:
我想将一些事件/数据从父窗口发送到其子窗口.我该怎么办? 我已经尝试过 postMessage ,但是没有用.
I want to send some event/data from parent window to its child window. How can I do so? I have tried postMessage, but it didn't work.
答
它已经工作了,早些时候我在语法上犯了一些错误.这是相同的正确代码.
It has worked now, earlier I was doing some syntax mistake. Here is the correct code for the same.
//parent Window
childWindow=window.open("http:/localhost/abcd.php","_blank","width=500,height=500");
childWindow.postMessage('message',"http://localhost:80/child.php");
//child Window
var newUrl='';
window.addEventListener(
"message",
function(e) {
console.log(e.data);//your data is captured in e.data
}, false);