Answer the question
In order to leave comments, you need to log in
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(); //проигрываем звук
}
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question