Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect multiple chrome tabs opened of the same app 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?

like image 718
Vesko Vujovic Avatar asked Mar 02 '16 15:03

Vesko Vujovic


People also ask

How do you prevent a user from opening the same URL in multiple tabs in the same browser?

You cannot (and should not) do that. User can always just open use another browser or another computer to open another view onto the web site. So, basically you cannot ever prevent this. Your web-site should be able to handle multiple tabs viewing the same state.

Can you check how many tabs are open in Chrome?

Beside the answer of Mat, if you have a stylus (like Samsung Galaxy Note), you can also hover on the tabs [:D] button to see your open tabs count.

Can you search multiple tabs at once?

Highlight each worksheet tab you want to search by holding down the Ctrl key and clicking each tab you would like to search. Once each worksheet you want to search is highlighted, perform a Find, and all highlighted worksheets will be searched.


1 Answers

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

like image 57
jcubic Avatar answered Sep 30 '22 04:09

jcubic