aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/clients/openwindow
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/clients/openwindow
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/clients/openwindow')
-rw-r--r--files/zh-cn/web/api/clients/openwindow/index.html81
1 files changed, 81 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/clients/openwindow/index.html b/files/zh-cn/web/api/clients/openwindow/index.html
new file mode 100644
index 0000000000..18a85d7538
--- /dev/null
+++ b/files/zh-cn/web/api/clients/openwindow/index.html
@@ -0,0 +1,81 @@
+---
+title: Clients.openWindow()
+slug: Web/API/Clients/openWindow
+translation_of: Web/API/Clients/openWindow
+---
+<p>{{SeeCompatTable}}{{APIRef("Service Workers API")}}</p>
+
+<p>{{domxref("Clients")}}接口的 <strong><code>openWindow()</code></strong> 方法创建一个顶级的浏览器上下文并加载给定的 URL. 如果调用脚本没有显示弹出窗口的权限, <strong><code>openWindow() </code></strong>将抛出 InvalidAccessError.</p>
+
+<p>在Firefox中,只有在作为通知点击事件的结果调用时,才允许该方法显示弹出窗口.</p>
+
+<p>在Chrome for Android中,该方法可以改为在先前添加到用户主屏幕的 <a href="https://developer.mozilla.org/en-US/Apps/Progressive/Installable">standalone web app</a> 提供的现有浏览上下文中打开URL.</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="brush: js">ServiceWorkerClients.openWindow(url).then(function(WindowClient) {
+ // do something with your WindowClient
+});</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt><code>url</code></dt>
+ <dd>一个 {{domxref("USVString")}} ,表示要在窗口中打开的client的URL。 通常,此值必须是与调用脚本有相同域的URL.</dd>
+</dl>
+
+<h3 id="返回值">返回值</h3>
+
+<dl>
+ <dd>如果URL来自与服务工作者相同的域,则resolve为 {{domxref("WindowClient")}} 对象的Promise,否则resolve为 {{Glossary("null", "null value")}} .</dd>
+</dl>
+
+<h2 id="示例">示例</h2>
+
+<pre class="brush: js">// When the user clicks a notification focus the window if it exists or open
+// a new one otherwise.
+onotificationclick = function(event) {
+ var found = false;
+ clients.matchAll().then(function(clientsArr) {
+ for (i = 0; i &lt; clientsArr.length; i++) {
+ if (clientsArr[i].url === event.data.url) {
+ // We already have a window to use, focus it.
+ found = true;
+ clientsArr[i].focus();
+ break;
+ }
+ }
+ if (!found) {
+ // Create a new window.
+ clients.openWindow(event.data.url).then(function(windowClient) {
+ // do something with the windowClient.
+ });
+ }
+ });
+};
+</pre>
+
+<h2 id="规范">规范</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('Service Workers', '#clients', 'Clients')}}</td>
+ <td>{{Spec2('Service Workers')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<div>
+
+
+<p>{{Compat("api.Clients.openWindow")}}</p>
+</div>