offline, cross-tab communication (javascript-only)

☆樱花仙子☆ 提交于 2019-11-30 20:50:15

问题


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.


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/19824379/offline-cross-tab-communication-javascript-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!