Javascript Web通知显示持续时间

Javascript Web通知显示持续时间,javascript,notifications,Javascript,Notifications,我正在向网络发送通知。如果用户未单击通知,我希望最多显示10分钟 我使用了setTimeout,但它会显示大约15秒,然后隐藏。 请引导我 这是我的代码: function notify(title, message, link) { var option = { body: message, dir: 'rtl', title: title, icon: '/Images/notification.png', }

我正在向网络发送通知。如果用户未单击通知,我希望最多显示10分钟

我使用了setTimeout,但它会显示大约15秒,然后隐藏。 请引导我

这是我的代码:

function notify(title, message, link) {
    var option = {
        body: message,
        dir: 'rtl',
        title: title,
        icon: '/Images/notification.png',
    }

    var notify = new Notification(title, option);

    notify.onclick = function () {
        window.open(link, '_blank');
        notify.close();
    };

    notification.onshow = function () {
        setTimeout(notification.close, 600000);
    }
}

只需添加属性
requireInteraction

var option = {
    body: message,
    dir: 'rtl',
    title: title,
    icon: '/Images/notification.png',
    requireInteraction: true,
}
通知的requireInteraction只读属性 接口返回一个布尔值,指示通知应 保持活动状态,直到用户单击或取消它,而不是 自动关闭


请参见此处:

我已更新了您的代码。愿这对你有帮助

var options = {
            body: "My notification message",
            dir : "ltr",
            requireInteraction: true
};

var notify = new Notification('Hello User', options);
notify.onclick = function () {
    notify.close();
};

notify.onshow = function () {
    setTimeout(()=>{
        notify.close();
    }, 15000);
}