【问题标题】:How to play a notification alert sound when the browser window is minimized and when a notification comes from the server如何在浏览器窗口最小化以及通知来自服务器时播放通知警报声音
【发布时间】:2012-09-29 14:05:05
【问题描述】:

我有一个要求,只有在浏览器窗口最小化时才需要播放通知声音,类似于 GTalk 所做的。

我已经使用 JQuery 的 $(window).blur() 进行了尝试,但它只在我手动模糊它时播放,而不是在通知到来且窗口模糊时播放。

这是我尝试过的小提琴:http://jsfiddle.net/zfUnm/

其实这是一个聊天通知,只有在浏览器最小化时才需要播放。

提前致谢

【问题讨论】:

  • 你是如何从服务器获得通知的?

标签: javascript jquery html chat google-talk


【解决方案1】:

我认为他们在最小化时不会播放它。每次收到新通知时他们都会调用它,但是当窗口处于活动状态时,他们会禁用声音。

var isactive = false;

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

onNotificaitonComes = playSound;

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

你可以在这里找到更多方法Is there a way to detect if a browser window is not currently active?

【讨论】:

    猜你喜欢
    • 2016-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多