aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/wakelock/request
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/wakelock/request
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/wakelock/request')
-rw-r--r--files/zh-cn/web/api/wakelock/request/index.html86
1 files changed, 86 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/wakelock/request/index.html b/files/zh-cn/web/api/wakelock/request/index.html
new file mode 100644
index 0000000000..11605b1ab9
--- /dev/null
+++ b/files/zh-cn/web/api/wakelock/request/index.html
@@ -0,0 +1,86 @@
+---
+title: WakeLock.request()
+slug: Web/API/WakeLock/request
+translation_of: Web/API/WakeLock/request
+---
+<p>{{APIRef("Screen Wake Lock API")}}{{SeeCompatTable}}{{securecontext_header}}</p>
+
+<p><span class="seoSummary"><strong><code>WakeLock.request()</code></strong> 方法用来获取屏幕唤醒锁定权限,防止屏幕变暗、关闭或展示屏幕保护程序。</span></p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox notranslate"><em>WakeLock</em>.request(<var>wakeLockType</var>)</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt><code><var>wakeLockType</var></code></dt>
+ <dd>唤醒锁定类型,目前必须传 <code>"screen"</code> 。</dd>
+</dl>
+
+<h3 id="返回值">返回值</h3>
+
+<p>决议为 {{DOMxRef("WakeLockSentinel")}} 的 {{JSxRef("Promise")}}。</p>
+
+<h3 id="异常">异常</h3>
+
+<dl>
+ <dt><code>NotAllowedError</code></dt>
+ <dd>当唤醒锁定不可用的时候抛出,例如在:
+ <ul>
+ <li>由于屏幕唤醒锁定策略,Document 不允许使用屏幕唤醒锁定。</li>
+ <li>Document 不完全激活。</li>
+ <li>Document 被隐藏。</li>
+ <li>{{Glossary("User Agent")}} 无法获取平台的唤醒锁定。</li>
+ </ul>
+ </dd>
+</dl>
+
+<h2 id="示例">示例</h2>
+
+<p>以下示例获取屏幕唤醒锁定并在 10 分钟后释放它:</p>
+
+<pre class="notranslate">function tryKeepScreenAlive(minutes) {
+ navigator.wakeLock.request("screen").then(lock =&gt; {
+ setTimeout(() =&gt; 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-request">Screen Wake Lock API</a></td>
+ <td>Editor's Draft</td>
+ <td>Initial specification.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+
+
+<p>{{Compat("api.WakeLock.request")}}</p>
+
+<h2 id="相关链接">相关链接</h2>
+
+<ul>
+ <li>{{DOMxRef("WakeLock")}}</li>
+ <li>{{DOMxRef("Navigator.wakeLock")}}</li>
+</ul>
+
+<p>
+ <audio style="display: none;"></audio>
+</p>