我有一个html页面(main.html)使用带有window.open("newtab.html")方法的javascript在同一个域中打开一个新选项卡.
在新选项卡中,用户单击按钮执行结束活动的操作.此时我想向开启窗口发送消息.我尝试使用postMessage但是从新标签我不能引用开启者.
从新标签我喜欢的东西,但我"ko"
var w = window.opener;
if (w) {
w.postMessage("hi", "http://10.150.10.43");
} else {
alert("ko");
}
Run Code Online (Sandbox Code Playgroud)
将消息从辅助选项卡/窗口发送到主选项卡(在同一域中)的最佳方法是什么?
非常感谢Luca