我想从父窗口发送一些事件/数据到它的子窗口。我该怎么做?
我试过postMessage,但没用。
最佳答案
它现在起作用了,之前我犯了一些语法错误。这是相同的正确代码。
//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);
关于javascript - 如何将事件从父窗口发送到其子窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49516556/