0

I have two windows: window A and window B.

window A and window B are active on the same Web-browser.

window A contains a script.

Questions:

Is it possible for window A to listen to events that are happening in windows B such as keyup?

Please provide some explanation.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

3 Answers3

1

In window B you set a cookie and in window A you create a setTimeout function that every "x" milliseconds check if there are any new cookie.

Look at this: Javascript communication between browser tabs/windows

Community
  • 1
  • 1
David Ginanni
  • 1,617
  • 15
  • 9
  • 3
    That's a pretty messy solution, but I like it! What else is JavaScript for than messy solutions, right? – BoltKey Sep 04 '17 at 20:08
  • Consider `window`'s storage event https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_event – giovannipds Jan 10 '20 at 15:15
0

If window A is a parent of window B (A opened B) then it's possible to find the element and add event listener. Also you can use postMessage to communticate between windows.

Pavel Staselun
  • 1,970
  • 1
  • 12
  • 24
0

Window A can listen to Window B events using sockets, checkout socket.io library. Where we need to emit an event and listen across all windows or specific windows can be possible using this library.