admin管理员组文章数量:1290941
Is there a chance to use window.postmessage() to municate between two different applications in different tabs in the same browser?
I know you can do it between application and iFrame, but how about different tabs?
Update:
Case scenario:
user plays audio from vk in one tab
user starts playing video from youtube in another tab
youtube sends postmessage() to vk that video started playing
- vk makes audio silent
Thanks
Is there a chance to use window.postmessage() to municate between two different applications in different tabs in the same browser?
I know you can do it between application and iFrame, but how about different tabs?
Update:
Case scenario:
user plays audio from vk. in one tab
user starts playing video from youtube. in another tab
youtube. sends postmessage() to vk. that video started playing
- vk. makes audio silent
Thanks
Share Improve this question edited Aug 12, 2014 at 21:48 inside asked Aug 12, 2014 at 18:10 insideinside 3,17712 gold badges51 silver badges76 bronze badges 2- Have you seen stackoverflow./questions/3203530/… ? – Casey Falk Commented Aug 12, 2014 at 18:16
- thanks, that was 4 years ago, so I was hoping for an update. – inside Commented Aug 12, 2014 at 18:20
2 Answers
Reset to default 10It can be done if you use an "intermediate page" loaded in an iFrame.
The (theoretical) solution uses two separate methods of inter-page munication:
window.postMessage()
localStorage
orsessionStorage
- see this guide for how this works; the technique involves setting values in one iFrame, and listening for events in the other iFrame.
The "intermediate page" acts as a proxy, translating message events into localStorage events, and vice-versa. If you load this "intermediate page" in an iFrame from both pages, then any messages you post in one tab will pop out in the other tab:
[Tab 1] --(postMessage)--> [iFrame 1]
|
(localStorage)
|
v
[iFrame 2] --(postMessage)--> [Tab 2]
If one of the tabs is on the same domain as the intermediate page (illustrated here as Tab 2
), this can be simplified (without affecting the other tab's setup).
[Tab 1] --(postMessage)--> [iFrame 1]
|
(localStorage)
|
v
[Tab 2]
following up this thread. Same situation here. Opening a different origin using window.open("originB") from origin A. As Lakhan Jain said, theoretically we can use window.postMessage() (https://developer.mozilla/en-US/docs/Web/API/Window/postMessage) for municating between windows with different origins. we would just need to have the reference of the other window.
The problem is that we are not able to listen the events that e from the origin A even if we delay the postMessage until origin B is fully loaded.
本文标签: javascriptwindowpostmessage() to communicate between applications in different tabsStack Overflow
版权声明:本文标题:javascript - window.postmessage() to communicate between applications in different tabs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741514783a2382818.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论