是否有一个设置可以让我保持通知打开状态直到用户单击它?
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/