Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 postMessage without window reference

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.

like image 898
Dennis C Avatar asked Dec 07 '25 06:12

Dennis C


1 Answers

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.

like image 62
Dennis C Avatar answered Dec 08 '25 20:12

Dennis C



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!