aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/notification/requireinteraction/index.html
blob: 2d5bf85e6d60d187886ddd33175faec89b06f31d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
---
title: Notification.requireInteraction
slug: Web/API/notification/requireInteraction
tags:
  - Notification
  - 属性
  - 网页
translation_of: Web/API/Notification/requireInteraction
---
<p>{{APIRef("Web Notifications")}}{{AvailableInWorkers}}{{securecontext_header}}</p>

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

<div class="note">
<p><strong>注意</strong>: 此属性可以在创建通知时通过在 {{domxref("Notification.Notification()")}} 构造器的 options 参数接收的对象上设置 <code>requireInteraction</code> 属性为 <code>true</code> 来进行设置</p>
</div>

<h2 id="Syntax" name="Syntax">语法</h2>

<pre class="brush: js notranslate">function spawnNotification(theTitle,theBody,shouldRequireInteraction) {
  var options = {
      body: theBody, //通知正文
      requireInteraction: shouldRequireInteraction //在此处设置 requireInteraction
  }
  var n = new Notification(theTitle,options);
}</pre>

<h3 id="Return_Value" name="Return_Value"></h3>

<p>{{jsxref("Boolean")}} (布尔值)。</p>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">规范</th>
   <th scope="col">状态</th>
   <th scope="col">意见</th>
  </tr>
  <tr>
   <td>{{SpecName('Web Notifications','#dom-notification-requireinteraction','requireInteraction')}}</td>
   <td>{{Spec2('Web Notifications')}}</td>
   <td>现今标准</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器支持">浏览器支持</h2>

<p>{{Compat("api.Notification.requireInteraction")}}</p>

<h2 id="相关内容">相关内容</h2>

<ul>
 <li><a href="/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API">使用 Notifications API</a></li>
</ul>