Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在卸载页面之前关闭页面的所有通知(不使用Window#onunload)?_Javascript_Html_Google Chrome_Notifications - Fatal编程技术网

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

Javascript 如何在卸载页面之前关闭页面的所有通知(不使用Window#onunload)?,javascript,html,google-chrome,notifications,Javascript,Html,Google Chrome,Notifications,我有一个页面,通过使用通知用户服务器更新 它不是谷歌浏览器的扩展 我想在卸载页面之前关闭所有页面通知。 我正试图通过以下方式实现: var notifications = new Array(); // ... var popup = window.webkitNotifications.createNotification(...); // ... notifications.push(popup); // ... function closeAll(){ for (notificat

我有一个页面,通过使用通知用户服务器更新

它不是谷歌浏览器的扩展

我想在卸载页面之前关闭所有页面通知。 我正试图通过以下方式实现:

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();
});
但当我重新加载页面时,通知不会关闭。 我在Chromium项目中发现了这个问题:


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

使用
beforeunload
事件而不是
unload
我想知道您是否可以在通知弹出窗口中添加一些javascript并在实际弹出窗口中设置超时,这样它最终会关闭

我必须试着测试一下。

使用这个:)


我今天遇到了这个问题,这个bug似乎也没有被修复过,糟透了。如果用户刷新页面,通知就留在那里。你有没有找到解决办法?
$(window).on('beforeunload', function() {
    closeAll();
});