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:
- What's the problem with the above-tried approach.
- If it's not possible by the above approach, how to do this?