【问题标题】:How can I show notifications for longer than the default timeout?如何显示通知的时间超过默认超时?
【发布时间】:2016-11-18 16:20:18
【问题描述】:

我想向用户显示 HTML5 通知的时间超过默认时间。我已将超时设置为 30 秒,但浏览器在运行完整时间之前清除通知。如何延长通知时间?

function testNotification() {
  var callNotification = new Notification('Notification Title', {
    body: "Notification Body"
  });
  setTimeout(function() {
    callNotification.close();
  }, 30000);
}

【问题讨论】:

    标签: javascript notifications


    【解决方案1】:

    requireInteraction 添加到通知选项,顾名思义,需要用户进行交互才能关闭通知。如果用户不手动关闭通知,它将在超时到期后关闭。

    function testNotification() {
      var callNotification = new Notification('Notification Title', {
        body: "Notification Body",
        requireInteraction: true
      });
      setTimeout(function() {
        callNotification.close();
      }, 30000);
    }
    

    【讨论】:

      猜你喜欢
      • 2011-08-02
      • 2017-08-24
      • 1970-01-01
      • 1970-01-01
      • 2014-07-18
      • 2011-11-18
      • 1970-01-01
      • 2012-02-12
      相关资源
      最近更新 更多