防止 chrome.notifications API 在几秒钟后隐藏我的通知 [英] Prevent chrome.notifications API from hiding my notification after a few seconds

查看:36
本文介绍了防止 chrome.notifications API 在几秒钟后隐藏我的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我每天大约会发送 1-2 条通知,重要的是用户不会错过它.有没有办法去掉自动关闭,只允许用户手动关闭通知?

I'm doing around 1-2 notifications a day and it's important the user doesn't miss it. Is there a way of removing the auto close and only allowing the user to manually close the notification?

我在通知选项中没有看到任何选项:

I don's see any option for this in the Notification Options:

http://developer.chrome.com/extensions/notifications.html#类型通知选项

推荐答案

Notification 现在有(自 Chrome 50 起)requireInteraction 属性 强制通知停留在屏幕上:

Notification now has (since Chrome 50) a requireInteraction property to force the notification to stay on screen:

var notification = new Notification("TITLE", {
          icon: 'assets/res/icon.png',
          body: "MESSAGE",
          requireInteraction: true     
});

onclick 中,您必须关闭通知:

In onclick you have to close the notification:

notification.onclick = function()
{
    this.close();
}

这篇关于防止 chrome.notifications API 在几秒钟后隐藏我的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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