HTML5 postMessage without window reference

拥有回忆 提交于 2019-12-10 10:41:05

问题


The HTML5 postMesssage API allows sending message between window opener and openee. However, it requires reference/linkage to the receiver window.

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

  • 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)

Is there a API I missed?

BTW, No cross-domain is need. I am thinking of same domain, multiple open by user.


回答1:


For whom is looking for workaround solution.

I end up using window.localStorage (not even sessionStorage) and use the onstorage trigger my event handler.

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.



来源:https://stackoverflow.com/questions/17356681/html5-postmessage-without-window-reference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!