0

I am trying to create a communication channel between tabs. In my main tab I have the following:

window.addEventListener("message", (event) => {
   console.log(event.data);
}, false);

I am opening new tab using this code:

window.open('https://localhost/newtab.html', '_blank');

In the newtab.html I hav this code:

<html>
  <body>
    <script>
        window.postMessage('message', 'abc');
    </script>
  </body>
</html>

Both target tab and new tab are on the same domain. I am not getting into target tab when opening a new tab. What am I missing?

Thanks

Mark
  • 4,535
  • 7
  • 39
  • 76
  • Does this answer your question? [Communication between tabs or windows](https://stackoverflow.com/questions/28230845/communication-between-tabs-or-windows) – patrickb Jan 27 '22 at 11:28
  • I tried localStorage, postMesasge, BroadcastChannel. All the same. I am not getting into the Listener on the main tab. Seems to me it doesn't like that script code I am using in the new tab, or something else. – Mark Jan 27 '22 at 12:03
  • 1
    This may help someone - https://stackoverflow.com/questions/66473527/session-storage-not-getting-carried-forward-to-new-tab-in-chrome-89 – rcrahul Aug 02 '23 at 16:50

0 Answers0