Question

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.

Was it helpful?

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.

OTHER TIPS

In 2021, you can use service worker:

https://github.com/gyteng/service-worker-event

notice: service worker only works in https protocol

localStorage can be used to track windows. You should take into account a situation when window crashes - it will leave the garbage in localStorage. Accessing a common resource from several windows simultaneously may be done by mutex based on localStorage.

I've recently published the interwindow communication library (all features are described in readme). It provides thread-safe data sharing, cross-window locks and event broadcasting. It also solves some IE issues.

Broadcast Channel is design for this https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API

but the native api only support modern browsers. there is a npm package support all old browsers as well https://www.npmjs.com/package/broadcast-channel

You don't have control over that. The user can do basically whatever he/she wants on the computer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top