offline, cross-tab communication (javascript-only)(离线、交叉表通信(仅限 JavaScript))
问题描述
是否可以找到某些网站的外国实例?这些是独立打开的选项卡(不是通过 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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:离线、交叉表通信(仅限 JavaScript)


- 失败的 Canvas 360 jquery 插件 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01