blob: 41697e4c71b3e63dd6a76763646825f7ebc6207b (
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
|
---
title: WakeLock
slug: Web/API/WakeLock
translation_of: Web/API/WakeLock
---
<p>{{APIRef("Screen Wake Lock API")}}{{SeeCompatTable}}{{securecontext_header}}</p>
<p><span class="seoSummary"><code><strong>WakeLock</strong></code> 接口允许一个文件获取屏幕唤醒锁定。</span></p>
<h2 id="方法">方法</h2>
<dl>
<dt>{{domxref("WakeLock.request","WakeLock.request()")}}</dt>
<dd>返回一个决议为 {{DOMxRef("WakeLockSentinel")}} 的 {{JSxRef("Promise")}} 或当唤醒锁定不可访问的时候抛出异常。</dd>
</dl>
<h2 id="示例">示例</h2>
<p>以下例子获取一个唤醒锁定并在 10 分钟后释放它:</p>
<pre class="notranslate">function tryKeepScreenAlive(minutes) {
navigator.wakeLock.request("screen").then(lock => {
setTimeout(() => lock.release(), minutes * 60 * 1000);
});
}
tryKeepScreenAlive(10);
</pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">规范</th>
<th scope="col">状态</th>
<th scope="col">Comment</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://w3c.github.io/screen-wake-lock/#dom-wakelock">Screen Wake Lock API</a></td>
<td>Editor's Draft</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<div>
<p>{{Compat("api.WakeLock")}}</p>
<h2 id="相关链接">相关链接</h2>
<ul>
<li>{{DOMxRef("Navigator.wakeLock")}}</li>
</ul>
</div>
|