1

I have a requirement where i need to play a notification sound only when the browser window is minimized similar to what GTalk does.

I've tried it using JQuery's $(window).blur() but it only plays it when I manually blur it but not when the notifications comes and the window is blurred.

Here is the fiddle that I have tried: http://jsfiddle.net/zfUnm/

Actually this is a chat notification that i have to play only when the browser is minimized.

Thanks in advance

Abilash
  • 6,089
  • 6
  • 25
  • 30

1 Answers1

3

I think they don't play it when minimize. They will call it every time the new notification comes, but when window is active, they disable the sound.

var isactive = false;

function playSound(){
    if (isactive) return;
    playWav...;
}

onNotificaitonComes = playSound;

$(window).focus(function(){
    isactive = true;
}).blur(function(){
    isactive = false;
});

You can find out more method here Is there a way to detect if a browser window is not currently active?

Community
  • 1
  • 1
James
  • 13,571
  • 6
  • 61
  • 83