0

I am using Mobile and Desktop Browsers, When web page opens a socket connection will be established with server. Working fine the browser is in foregroud.

But, when user minimizes the Browser then still that socket is still connected.

What I want is Disconnect socket when Browser goes to background, Just disconnect socket and connect socket back when browser comes back to foreground.

Thanksfor your help!

Jitendra Khatri
  • 774
  • 3
  • 16
  • What about: document.addEventListener("visibilitychange", function() { // close websocket connection here.. }, false); – Ran Hassid Jul 18 '16 at 07:57

1 Answers1

0

You can read here how to cache the event when the window is not active anymore. In the event handler just call the api which close your socket connection.

Hope it helps.

Community
  • 1
  • 1
Ran Hassid
  • 2,788
  • 1
  • 12
  • 20