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