A
A
antirek2015-10-27 08:18:01
JavaScript
antirek, 2015-10-27 08:18:01

Is there a js library to run js in only one tab?

Situation: there is a js code that listens to events on websockets when a page is opened. When opening an additional tab with the same page, one more websocket connection will be opened, and this is superfluous, because. when an event arrives via websocket, notifications are shown, i.e. there will be overlap.
Is there a js library that keeps track that there is an open page in a tab? And executes the code if there is no other tab or that tab is closed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Immortal_pony, 2015-10-27
@Immortal_pony

https://github.com/ai/visibilityjs
https://github.com/studentIvan/dueljs

R
RubaXa, 2015-10-27
@RubaXa

You need a Master / Slave, you can implement it using:
- SharedWorker + fallback in localStorage and / or LocalConnection (Flash) - if you do it yourself
- BNC Connector - theprivateland.com/bncconnector/home.htm
- Intercom.js - https:// github.com/diy/intercom.js/ (working with sockets out of the box)
- Wormhole.js - https://github.com/RubaXa/wormhole (in development, demo )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question