没有窗口引用的HTML5 postMessage [英] HTML5 postMessage without window reference
问题描述
HTML5 postMesssage API 允许在开窗器和openee之间发送消息。但是,它需要引用/链接到接收器窗口。
The HTML5 postMesssage API allows sending message between window opener and openee. However, it requires reference/linkage to the receiver window.
是否有纯客户端JavaScript方式向所有窗口订户广播事件,在用户打开的相同的doaminname下(例如Duplicate Tab)相同的会话,没有服务器的帮助?
Is there a pure client side JavaScript way to broadcast events to all window subscriber, under same doaminname, opened by user (e.g. Duplicate Tab) same session, without help of server?
现在,我想出了一些想法
For now, I come up with few ideas
- 服务器端频道(通过$ _SESSION)和民意调查
- JS烹饪更新和民意调查(硬饼干播放)
- localstorage更新和投票(甚至最差)
- WebRTC? (浏览器支持不佳)
- Server side channel (by $_SESSION) and polling
- JS Cooking update and polling (hard cookie play)
- localstorage update and polling (even worst)
- WebRTC? (poor browser support)
我错过了一个API吗?
Is there a API I missed?
顺便说一句,不需要跨域。我想的是同一个域,用户多次打开。
BTW, No cross-domain is need. I am thinking of same domain, multiple open by user.
推荐答案
为谁寻找解决方案解决方案。
For whom is looking for workaround solution.
我最终使用 window.localStorage (甚至不是sessionStorage)并使用onstorage触发我的事件处理程序。
I end up using window.localStorage (not even sessionStorage) and use the onstorage trigger my event handler.
在某些浏览器上有一些关于会话隔离的问题(好吧,我的意思是IE),sessionStorage上的更改可能会或可能不会分派到另一个窗口。同时localStorage做得更好。
There is some problem about session isolation on some browser(well, I mean IE), that the change on sessionStorage may or may not dispatch to another window. Meanwhile localStorage does better.
这篇关于没有窗口引用的HTML5 postMessage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!