D
D
Dmitry Petrik2015-04-06 07:53:52
JavaScript
Dmitry Petrik, 2015-04-06 07:53:52

Chat. How to play a notification sound if the browser window is minimized?

The task is this. If the user was written to the chat, and the browser window is minimized or the user is on another tab, then you need to play the notification sound. With another tab, I solved the problem like this:

var isActive;
    window.onfocus = function () { 
        isActive = true; 
    }; 
    window.onblur = function () { 
        isActive = false; 
    }; 
    
    if(!window.isActive){
       notify();  //проигрываем звук
    }


But if the user stayed on the chat tab, but turned off the browser, then this option stops working. How to track whether the browser is minimized or maximized?

UPD . Decision

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-04-06
@butteff

You can save the time of the last user action, clicks, keyboard button presses, etc. to a variable. If the timeout is long, then it is not in the window or it is minimized. Then play the sound.
Of course, this will not be accurate. But in another way, I do not know how to solve the problem, it seems that there is no way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question