有没有办法检测同一应用程序的多个浏览器标签页是否已打开。
假设我有一个名为www.test.com的网站,并且我打开了4个标签页。
有没有办法在JavaScript中检测到已打开多个标签页?
有没有办法检测同一应用程序的多个浏览器标签页是否已打开。
假设我有一个名为www.test.com的网站,并且我打开了4个标签页。
有没有办法在JavaScript中检测到已打开多个标签页?
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');
确实有一种方法,但不能保证总是正确:
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);
};