LEE
LEE

Reputation: 3605

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,

The new_url page had a button on it. When I clicked that button, I use 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'); 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. If yes, then how?

Upvotes: 0

Views: 1309

Answers (1)

LEE
LEE

Reputation: 3605

Fixed!

Use window.opener.postMessage("some data", "*"); in your child tab.

window.opener is the solution.

Upvotes: 1

Related Questions