blob: 66b7c523398428faf667ec7c4667a942034fd134 (
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
|
---
title: alarms
slug: Mozilla/Add-ons/WebExtensions/API/alarms
translation_of: Mozilla/Add-ons/WebExtensions/API/alarms
---
<div>{{AddonSidebar}}</div>
<p>在未来一个特定的时间运行的计划任务代码。这很像<code><a href="/zh-CN/docs/Web/API/WindowTimers/setTimeout">setTimeout()</a></code>和<code><a href="/zh-CN/docs/Web/API/WindowTimers/setInterval">setInterval()</a></code>,不过这些函数仅可以按需使用而不能在后台页面工作。</p>
<p>想要使用这个API,您需要获取"alarms"的<a href="/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions">permission</a>。</p>
<h2 id="类型">类型</h2>
<dl>
<dt>{{WebExtAPIRef("alarms.Alarm")}}</dt>
<dd>Information about a particular alarm.</dd>
</dl>
<h2 id="方法">方法</h2>
<dl>
<dt>{{WebExtAPIRef("alarms.create()")}}</dt>
<dd>创建新的alarm.</dd>
<dt>{{WebExtAPIRef("alarms.get()")}}</dt>
<dd>通过名称获取指定的alarm.</dd>
<dt>{{WebExtAPIRef("alarms.getAll()")}}</dt>
<dd>获取所有的alarm.</dd>
<dt>{{WebExtAPIRef("alarms.clear()")}}</dt>
<dd>清除指定名称的alarm.</dd>
<dt>{{WebExtAPIRef("alarms.clearAll()")}}</dt>
<dd>清除所有的alarm.</dd>
</dl>
<h2 id="事件">事件</h2>
<dl>
<dt>{{WebExtAPIRef("alarms.onAlarm")}}</dt>
<dd>当alarm发生的时候触发.</dd>
</dl>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p>{{Compat("webextensions.api.alarms")}}</p>
<div class="hidden note">
<p>The "Chrome incompatibilities" section is included from <a href="https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Chrome_incompatibilities"> https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Chrome_incompatibilities</a> using the <a href="/en-US/docs/Template:WebExtChromeCompat">WebExtChromeCompat</a> macro.</p>
<p>If you need to update this content, edit <a href="https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Chrome_incompatibilities">https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Chrome_incompatibilities</a>, then shift-refresh this page to see your changes.</p>
</div>
<p> {{WebExtExamples("h2")}}</p>
<div class="note"><strong>Acknowledgements</strong>
<p>This API is based on Chromium's <a href="https://developer.chrome.com/extensions/alarms"><code>chrome.alarms</code></a> API.</p>
<p>Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.</p>
</div>
|