如何设置通知扩展的关闭时间 chrome
How to set a closing time for notification extension chrome
我正在开发一个带有 chrome.notifications 的扩展程序,我想设置一个关闭通知的时间,我该怎么做?
Chrome 自动 隐藏 通知。它在屏幕上停留的时间取决于 priority
属性。请注意,除了 Chrome OS 之外的所有地方,隐藏通知都已有效关闭,因为 Notification Center was removed.
可以保持显示通知,但您必须求助于 dirty tricks. If you don't want to do it the hard way, consider using Web Notifications - 它们不会被隐藏。
更新: chrome.notifications
和 Web Notifications API 现在都实现了一个布尔标志 requireInteraction
,它定义了 Chrome 是否会淡出通知是否自动。
您仍然可以通过使用通知 ID 调用 chrome.notifications.clear()
来手动 关闭(即完全删除)通知。
要安排一些事情,您可以使用 DOM 间隔,或 chrome.alarms
API.
我正在我的项目中使用它
var opt = {type, title, message, etc....}
chrome.notifications.create("", opt, function(id) {
timer = setTimeout(function(){chrome.notifications.clear(id);}, 2000);
});
通知在 2 秒(2000 毫秒)后关闭
我正在开发一个带有 chrome.notifications 的扩展程序,我想设置一个关闭通知的时间,我该怎么做?
Chrome 自动 隐藏 通知。它在屏幕上停留的时间取决于 priority
属性。请注意,除了 Chrome OS 之外的所有地方,隐藏通知都已有效关闭,因为 Notification Center was removed.
可以保持显示通知,但您必须求助于 dirty tricks. If you don't want to do it the hard way, consider using Web Notifications - 它们不会被隐藏。
更新: chrome.notifications
和 Web Notifications API 现在都实现了一个布尔标志 requireInteraction
,它定义了 Chrome 是否会淡出通知是否自动。
您仍然可以通过使用通知 ID 调用 chrome.notifications.clear()
来手动 关闭(即完全删除)通知。
要安排一些事情,您可以使用 DOM 间隔,或 chrome.alarms
API.
我正在我的项目中使用它
var opt = {type, title, message, etc....}
chrome.notifications.create("", opt, function(id) {
timer = setTimeout(function(){chrome.notifications.clear(id);}, 2000);
});
通知在 2 秒(2000 毫秒)后关闭