Send data from one tab to another cross domain

Viewed 207

Need to find the solution for the below scenario.

On click on a button, a new window of different domain will open in a new tab. I want to send some data from the initial window to this new window.

Solution Tried: Sending data using window.postMessage from initial tab and trying to listen to that message event on a new window. Somehow not able to listen to that event.

--- On click of a button
 const windowObjectReference = window.open('http://localhost:7000/elmo/experiment');
  windowObjectReference.postMessage('message data');

--- On listener side
 window.addEventListener('message', (e) {
   console.log('*********************** data', e.data);
 }, false);

Expectation:

  1. What's the problem with the above-tried approach.
  2. If it's not possible by the above approach, how to do this?
0 Answers
Related