DEV Community

Discussion on: Super simple communication between tabs, windows or iframes

Collapse
 
stroemdev profile image
Simon Ström

Well, depending on the use case the postMessage of window might be better. Since that is supported across browsers and you can work across origins. The real benefit of this is that you do not need access to the window object, for example running when running your application in multiple windows. The easiest way to demo was through iframes though.

This type of events that should be broadcasted might be a bit rare, could be regarding a session so you can log out of every instance at once. Or something like a dark theme toggle you can change all windows at once, but when using several iframes on the same page and you need to communicate they might be more coupled around one specific task, and should only communicate between each other. Not to any iframes on a diffrent tab or window. (Sorry for the long answer)