Google chrome extension 是否在显示下一个通知之前关闭当前通知?

Google chrome extension 是否在显示下一个通知之前关闭当前通知?,google-chrome-extension,Google Chrome Extension,我触发通知,通知会自动关闭并超时 但是,某些通知将在超时完成之前发出 那么,如何在显示下一个通知之前关闭当前通知 我只希望在任何特定时间显示一个 背景: chrome.extension.onMessage.addListener(function(request, sender, sendResponse) { var notify = webkitNotifications.createNotification('icon-48.png', 'Notification', requ

我触发通知,通知会自动关闭并超时

但是,某些通知将在超时完成之前发出

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

我只希望在任何特定时间显示一个

背景:

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

尝试将notify 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);
});

@kdrureidy谢谢!正如广告所宣传的那样。接下来,将介绍如何在Ajax调用成功完成时取消通知。