Notification.requireInteraction

Note: 此特性在 Web Worker 中可用。

Secure context
This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

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 (布尔值)。

规范

规范 状态 意见
Notifications API
requireInteraction
Living Standard 现今标准

浏览器支持

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
requireInteractionChrome Full support YesEdge Full support 17Firefox No support NoIE No support NoOpera Full support YesSafari ? WebView Android No support NoChrome Android Full support YesFirefox Android No support NoOpera Android Full support YesSafari iOS No support NoSamsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

相关内容