离线、交叉表通信(仅限 JavaScript) [英] offline, cross-tab communication (javascript-only)

查看:22
本文介绍了离线、交叉表通信(仅限 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.keyevent.newValueevent.oldValue.

这仅适用于现代浏览器.

This only works in modern browsers.

这篇关于离线、交叉表通信(仅限 JavaScript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆