Search code examples
javascripttabsinstanceclient-sidecommunication

offline, cross-tab communication (javascript-only)


Is it possible to find foreign instances of certain website? Ofc theese are independently opened tabs (not by window.open). I need to prevent user from opening 2 tabs, and send message to previously opened tab to inform that it's impossible to open 2 tabs. 2 Intependent tabs may break page offline storage and webSQL structure, so that I can't allow people to use 2 tabs. It's also semi-offline app so it needs to be client-side solution.


Solution

  • You can communicate across tabs using localStorage. Every time you write a value, a "storage" event is fired on the window object on every tab (except the current one).

    http://diveintohtml5.info/storage.html

    Scroll down to "Tracking changes in the html5 storage area"

    The event will include event.key, event.newValue, event.oldValue.

    This only works in modern browsers.