简体   繁体   English

从由父选项卡打开的子选项卡页面接收数据-Javascript

[英]Receive data from a child tab page opened by the parent tab - Javascript

I was opening a link (called new_url) from my website by using an iframe , 我正在使用iframe从我的网站打开一个链接(称为new_url),

The new_url page had a button on it. new_url页面上有一个按钮。 When I clicked that button, I use parent.postMessage("some message", "*"); 当我单击该按钮时,我使用parent.postMessage("some message", "*"); to submit some data to my parent page and I received that using 提交一些数据到我的父页面,我收到了

  window.addEventListener('message', function(event) {


  }, false);

However, now, I'm not using iframe and using parent.window.open("new_url",'_newtab'); 但是,现在,我不使用iframeparent.window.open("new_url",'_newtab');使用parent.window.open("new_url",'_newtab'); instead. 代替。

My question is that can I received the data from the child tab in the parent tab the same way I received it in case of the iframe . 我的问题是,是否可以像在iframe一样从父选项卡的子选项卡中接收数据。 If yes, then how? 如果是,那怎么办?

Fixed! 固定!

Use window.opener.postMessage("some data", "*"); 使用window.opener.postMessage("some data", "*"); in your child tab. 在您的子标签中。

window.opener is the solution. window.opener是解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM