Notification.requireInteraction

备注: 此特性在 Web Worker 中可用

安全上下文: 此项功能仅在一些支持的浏览器安全上下文(HTTPS)中可用。

Notification 接口的 requireInteraction 属性是只读属性,它返回一个 Boolean(布尔值),指示在用户点击或关闭通知前,通知应该保持活动状态,而不是自动关闭。

备注: 此属性可以在创建通知时通过在 Notification.Notification() 构造器的 options 参数接收的对象上设置 requireInteraction 属性为 true 来进行设置

语法

function spawnNotification(theTitle,theBody,shouldRequireInteraction) {
  var options = {
      body: theBody, //通知正文
      requireInteraction: shouldRequireInteraction //在此处设置 requireInteraction
  }
  var n = new Notification(theTitle,options);
}

Boolean(布尔值)。

规范

Specification
Notifications API Standard
# dom-notification-requireinteraction

浏览器兼容性

BCD tables only load in the browser

相关内容