如何设置通知扩展名chrome的关闭时间

时间:2015-04-08 21:04:16

标签: google-chrome google-chrome-extension

我正在使用chrome开发扩展程序。通知想设置关闭通知的时间,我该怎么做?

2 个答案:

答案 0 :(得分:10)

Chrome会自动隐藏通知。它在屏幕上停留的时间取决于priority属性。请注意,除了Chrome操作系统以外,隐藏的通知都会有效关闭,如Notification Center was removed

可以保持显示的通知,,但您必须诉诸dirty tricks。如果您不想这么做,请考虑使用Web Notifications代替 - 它们不会被隐藏。

更新chrome.notifications和网络通知API现在都实现了一个布尔标记requireInteraction,用于定义Chrome是否会自动淡化通知。

您仍然可以通过使用通知ID调用chrome.notifications.clear()来手动关闭(即完全删除)通知。

要安排某些内容,您可以使用DOM间隔,也可以使用chrome.alarms API

答案 1 :(得分:5)

我在我的项目中使用它

var opt = {type, title, message, etc....}

chrome.notifications.create("", opt, function(id) {
    timer = setTimeout(function(){chrome.notifications.clear(id);}, 2000);
});

通知在2秒(2000毫秒)后关闭