Is there a way to detect if multiple browser tabs are opened of the same application.
Let's say i have www.test.com 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.com and i open 4 tabs of this website.
Is there a way to detect that multiple tabs are opened in JavaScript?
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');
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.