2013-10-14 28 views
0

我在超时时自动关闭消息。在下一个显示之前关闭当前通知?

但是,有些通知会在超时完成之前触发。

那么,如何在下一个显示之前关闭当前通知?

我只想在任何特定的时间显示一个。

背景:

chrome.extension.onMessage.addListener(function(request, sender, sendResponse) { 

    var notify = webkitNotifications.createNotification('icon-48.png', 'Notification', request.message); 

    notify.show(); 
    setTimeout(function(){ notify.cancel(); },10000); 
}); 

背景:

chrome.extension.sendMessage({ 

    message: "Fetching stuff from " + thestuffname}, 
    function(response) { 
    return response; 
}); 

回答

1

尽量使通知VAR全球,并创建一个新的

这样之前取消:

var notify; 

chrome.extension.onMessage.addListener(function(request, sender, sendResponse) { 
    if(notify){ 
     notify.cancel(); 
    } 
    notify = webkitNotifications.createNotification('icon-48.png', 'Notification', request.message); 

    notify.show(); 
    setTimeout(function(){ notify.cancel(); },10000); 
}); 
+1

@kdrureidy谢谢!按广告方式工作。接下来,将介绍如何在Ajax调用成功完成时取消通知。 – user1452893

+0

祝你好运:) – kdureidy