aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/notification/icon/index.html
blob: 40f76c90f0feb83b860ca4542ccfae00073401f6 (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
58
59
60
61
62
63
---
title: Notification.icon
slug: Web/API/notification/icon
tags:
  - API
  - Notification
translation_of: Web/API/Notification/icon
---
<p>{{APIRef("Web Notifications")}}</p>

<p>{{domxref("Notification")}}的只读属性<strong>icon</strong>使得包含<code>icon</code>的 URL 被显示成通知的一部分,如同指定{{domxref("Notification.Notification","Notification()")}}构造函数中<code>icon</code>的属性。</p>

<p>{{AvailableInWorkers}}</p>

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

<pre class="eval">var icon = Notification.icon;
</pre>

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

<p>一个 {{domxref("USVString")}}</p>

<h2 id="示例">示例</h2>

<p>在此<a href="https://github.com/mdn/emogotchi">示例</a>中,当我们想要发出一个通知时,我们运行一个简单的 <code>spawnNotification() 函数</code>——这是传递参数来指定我们想要的主体、图标和标题,然后它创建必要的<code>options</code>对象,并使用{{domxref("Notification.Notification","Notification()")}}构造函数来触发通知。</p>

<pre class="brush: js">function spawnNotification(theBody,theIcon,theTitle) {
  var options = {
      body: theBody,
      icon: theIcon
  }
  var n = new Notification(theTitle,options);
}</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('Web Notifications','#dom-notification-icon','icon')}}</td>
   <td>{{Spec2('Web Notifications')}}</td>
   <td>Living standard</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>



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

<h2 id="参见">参见</h2>

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