admin管理员组文章数量:1335847
Is there a way to detect if multiple browser tabs are opened of the same application.
Let's say i have www.test and i open 4 tabs of this website.
Is there a way to detect that multiple tabs are opened in JavaScript?
Is there a way to detect if multiple browser tabs are opened of the same application.
Let's say i have www.test. and i open 4 tabs of this website.
Is there a way to detect that multiple tabs are opened in JavaScript?
Share Improve this question asked Mar 2, 2016 at 15:13 Vesko VujovicVesko Vujovic 4001 gold badge7 silver badges24 bronze badges 1- Does this answer your question? Stop people having my website loaded on multiple tabs – Pere Joan Martorell Commented Feb 2, 2022 at 15:37
2 Answers
Reset to default 4You 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
There is, but it's not guaranteed to always be correct:
window.onload = function() {
var applicationCount = localStorage.getItem("applicationCount");
if (!applicationCount) {
applicationCount = 0;
}
localStorage.setItem("applicationCount", ++applicationCount);
}
window.onbeforeunload = function(e) {
var applicationCount = localStorage.getItem("applicationCount");
if (!applicationCount) {
applicationCount = 1;
}
localStorage.setItem("applicationCount", --applicationCount);
};
It uses the localStorage which is shared among the tabs. But note that if the browser crashes, the value is still saved.
本文标签: angularjsDetect multiple chrome tabs opened of the same app in javascriptStack Overflow
版权声明:本文标题:angularjs - Detect multiple chrome tabs opened of the same app in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742399655a2467628.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论