检测在javascript中为同一应用程序打开的多个Chrome标签页 [英] Detect multiple chrome tabs opened of the same app in javascript

查看:217
本文介绍了检测在javascript中为同一应用程序打开的多个Chrome标签页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以检测同一应用程序是否打开了多个浏览器选项卡.

Is there a way to detect if multiple browser tabs are opened of the same application.

假设我拥有www.test.com,并且打开了该网站的4个标签.

有没有一种方法可以检测到JavaScript中是否打开了多个选项卡?

Is there a way to detect that multiple tabs are opened in JavaScript?

推荐答案

您可以使用我的 sysend.js库,它使用localStorage在打开的标签页/窗口之间发送消息.所有要做的就是以下代码:

You can use my sysend.js library, it use localStorage to send messages between open tabs/windows. All to do is this code:

sysend.on('notification', function() {
   sysend.broadcast('multiple');
});
sysend.on('multiple', function() {
   // this will fire n-1 times if there are n tabs open if n > 1
   alert('multiple pages');
});
sysend.broadcast('notification');

JSFIDDLE

这篇关于检测在javascript中为同一应用程序打开的多个Chrome标签页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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