XWindow lets you communicate between tabs of same domain in real-time. This is done through HTML5 localStorage events which any tab in the same domain can listen to. Browsers supported: IE 9+, FF 4+, Chrome.
To broadcast a message
XWindow.broadcast("my custom message");
To listen to messages
XWindow.listen(function(payload){
console.log(payload.data);
});
- Can I send a JSON object?
Yes, you can send it as either JSON or plain string
- I don't want to broadcast, can I send it to just one tab?
Unfortunely, this is feature has been removed due to cross-browser issues. However you can implement a custom requestedBy-responseFor logic using a unique id internally in your JSON.
- I have multiple subscribers in the same tab, how can I cancel bubbling of the event to other subscribers?
Return false on listener:
XWindow.listen(function(payload){
console.log(payload.data);
return false;
});
Last listener will be invoked first for your convenience.
This library is released under the MIT License