如何在卸载之前关闭页面的所有通知(不使用Window#onunload)?

dio*_*cao 11 javascript html5 notifications google-chrome

我有一个页面,使用window.webkitNotifications通知用户有关服务器更新的信息.

它不是Google Chrome扩展程序.

我想在页面卸载前关闭所有页面通知.我正在努力做到:

var notifications = new Array();

// ...
var popup = window.webkitNotifications.createNotification(...);
// ...
notifications.push(popup);

// ...
function closeAll(){
  for (notification in notifications) {
    notifications[notification].cancel();
  }
}

//...
$(window).unload(function() {
  closeAll();
});
Run Code Online (Sandbox Code Playgroud)

但是当我重新加载页面时,通知没有关闭.我在Chromium项目中发现了这个问题:https://code.google.com/p/chromium/issues/detail? id = 40262

如何在不使用Window#onunload的情况下确保关闭页面通知?

tsq*_*rio 2

我想知道您是否可以在通知弹出窗口中添加一些 JavaScript 并在实际弹出窗口中设置超时,这样它最终会关闭。

我将不得不尝试并测试这一点。