eos87
eos87

Reputation: 9353

How to know if a user has more than one browser tab opened with my page?

Is there a way to know this only using Javascript? I'm trying to achieve something similar to Gmail's chat connected users list. If the user has more than one tab and then closes one, the closed tab doesn't affect the "connected" state of the user and still shows him/her in the chat list.

Upvotes: 2

Views: 578

Answers (2)

kwah
kwah

Reputation: 1149

Making use of (psuedo-)random names / identifiers onLoad, localStorage to keep a cross-tab / cross-window list of opened windows and beforeUnload to remove closed windows from the list would allow you to track how many windows are open. onFocus/onBlur would allow you to find out which one is currently active/inactive.

Upvotes: 0

Lime
Lime

Reputation: 13532

You will have to use server side technologies to have a cross browser experience that can detect the number of windows currently open for your site.

Basically you have to set it up like gmail and use ajax technologies to determine the activity/status of the current user and update it in a database. The implementation will vary on the technologies you are using.

Upvotes: 1

Related Questions