在下一个显示之前关闭当前通知?

时间:2013-10-14 03:45:50

标签: google-chrome-extension

我会发出超时自动关闭的通知。

但是,有些通知会在超时结束前触发。

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

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

背景:

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 个答案:

答案 0 :(得分:1)

尝试使notify var global,并在创建新的

之前取消它 像这样:

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);
});