gut*_*uto 7 google-chrome google-chrome-extension
我正在使用chrome开发扩展.通知想设置关闭通知的时间,我该怎么做?
Xan*_*Xan 10
Chrome会自动隐藏通知.它在屏幕上停留的时间取决于priority属性.请注意,除了Chrome操作系统之外,隐藏的通知都会被有效关闭,因为删除了通知中心.
可以保持显示的通知, 但你必须采取肮脏的技巧.如果您不想这么做,请考虑使用Web Notifications - 它们不会被隐藏.
更新:两者chrome.notifications和Web Notifications API现在都实现了一个布尔标志requireInteraction,用于定义Chrome是否会自动淡化通知.
您仍然可以通过使用通知ID 调用来手动关闭(即完全删除)chrome.notifications.clear()通知.
要安排某些事情,您可以使用DOM间隔或chrome.alarmsAPI.
我在我的项目中使用它
var opt = {type, title, message, etc....}
chrome.notifications.create("", opt, function(id) {
timer = setTimeout(function(){chrome.notifications.clear(id);}, 2000);
});
Run Code Online (Sandbox Code Playgroud)
通知在2秒后(2000毫秒)关闭
| 归档时间: |
|
| 查看次数: |
10291 次 |
| 最近记录: |