开发者

How can I close all notifications of a page before unload it (without use Window#onunload)?

I have a page that notifies the user about server updates, using window.webkitNotifications.

It's not a Google Chrome extension.

I want to close all page notifications before the page unload. I'm trying to do it with:

var notifications = new Array();

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

// ...
function closeAll(){
  for (no开发者_开发知识库tification in notifications) {
    notifications[notification].cancel();
  }
}

//...
$(window).unload(function() {
  closeAll();
});

But the notifications are not closed when I reloads the page. I found this issue on Chromium project: https://code.google.com/p/chromium/issues/detail?id=40262

How can I ensure that page notifications are closed without use the Window#onunload ?


I wonder if you can add some javascript to the notification popup and settimeout withing the actual popup, that way it will close eventually.

I will have to try and test this out.


Use this :)

$(window).on('beforeunload', function() {
    closeAll();
});


Use the beforeunload event instead of unload.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜