سؤال

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.

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top