可靠地解除Webkit通知 [英] Reliably Dismissing Webkit Notifications

查看:136
本文介绍了可靠地解除Webkit通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在成功创建和解除webkit通知,如下所示:

  notification = window.webkitNotifications.createNotification('foo。 png','bar','baz')
notification.show()
setTimeout - >
notification.cancel()
,3000

但是,通知不是'如果用户在这三秒钟内关闭或刷新页面,则会被解雇,并且他们会一直停留在桌面上,直到手动关闭。



有没有办法可靠地解雇他们使用 window.onunload window.onbeforeunload 处理程序,用于在页面关闭时清除通知。但是,这不会保留三秒钟的延迟,因为通知将在页面关闭时立即关闭。



另一个选项( 保留三秒延迟)是使用 createHTMLNotification(url)从HTML页面创建通知。通过在通知HTML文档中包含 setTimeout(window.close,3000)等脚本,让通知页面关闭本身。在这种情况下,显然,您的主页中不需要 setTimeout 调用,因为它已包含在通知中。


I'm successfully creating and dismissing webkit notifications like so:

notification = window.webkitNotifications.createNotification('foo.png', 'bar', 'baz')
notification.show()
setTimeout ->
    notification.cancel()
, 3000

However, the notifications aren't dismissed if the user closes or refreshes the page during those three seconds, and they stay on the desktop until manually closed.

Is there a way to reliably dismiss them under these circumstances?

解决方案

Use a window.onunload or window.onbeforeunload handler to clear the noifications when the page is closed. This does not preserve the three-second delay, however, since notifications will be closed immediately when the page closes.

Another option (that does preserve the three-second delay) is to create the notifications from HTML pages using createHTMLNotification(url). Have the notification page close itself by including a script like setTimeout(window.close, 3000) within the notification HTML document. In this case, obviously, you don't need a setTimeout call in your main page, since it is already included in the notification.

这篇关于可靠地解除Webkit通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆