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)


基础教程推荐
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01