offline, cross-tab communication (javascript-only)

前端 未结 3 1013
一向
一向 2021-01-07 08:26

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 s

相关标签:
3条回答
  • 2021-01-07 08:55

    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.

    0 讨论(0)
  • 2021-01-07 09:13

    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.

    0 讨论(0)
  • 2021-01-07 09:18

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

    0 讨论(0)
提交回复
热议问题