离线,跨表通讯(仅javascript) [英] offline, cross-tab communication (javascript-only)
问题描述
是否可以找到某些网站的外部实例? Ofc theese是独立打开的选项卡(不是window.open)。我需要阻止用户打开2个标签,并向先前打开的标签发送消息,以告知无法打开2个标签。 2个独立标签可能会破坏页面的离线存储和webSQL结构,因此我不允许人们使用2个标签。它也是半脱机应用程序,因此它必须是客户端解决方案。
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.
推荐答案
您可以使用localStorage在各个标签之间进行通信。每次您写一个值时,每个选项卡上的窗口对象(当前选项卡除外)都会触发一个存储事件。
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
向下滚动至跟踪html5存储区域中的更改
Scroll down to "Tracking changes in the html5 storage area"
该事件将包括 event.key
, event.newValue
, event.oldValue
。
仅在现代浏览器中有效。
This only works in modern browsers.
这篇关于离线,跨表通讯(仅javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!