gpt4 book ai didi

javascript - 如何使通知保持打开状态直到用户将其关闭?

转载 作者:行者123 更新时间:2023-11-28 13:14:34 25 4
gpt4 key购买 nike

是否有一个设置可以让我保持通知打开状态直到用户单击它?

                      if (("Notification" in window)) {

Notification.requestPermission(function() {
var notification =
new Notification('Hello',
{
body : 'Hello',
icon: 'https://www.domain.com/images/live_chat_icon.png',
tag: 'Test' ,
});

notification.onclick = function(event) {
event.preventDefault(); // prevent the browser from focusing the Notification's tab
window.open('https://www.domain.com', '_blank');
}
window.navigator.vibrate(500);
});
}

最佳答案

根据文档,有一个 bool 值requireInteraction:

A Boolean indicating that on devices with sufficiently large screens, a notification should remain active until the user clicks or dismisses it. https://developer.mozilla.org/en-US/docs/Web/API/notification

new Notification('Hello', { 
body : 'Hello',
requireInteraction: true
});

在 MacOS 上的 Chrome 中进行了测试。

关于javascript - 如何使通知保持打开状态直到用户将其关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39664740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com