diff options
| author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
|---|---|---|
| committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
| commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
| tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/mozilla/add-ons/webextensions/api/windows | |
| parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
| download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip | |
initial commit
Diffstat (limited to 'files/zh-cn/mozilla/add-ons/webextensions/api/windows')
4 files changed, 416 insertions, 0 deletions
diff --git a/files/zh-cn/mozilla/add-ons/webextensions/api/windows/create/index.html b/files/zh-cn/mozilla/add-ons/webextensions/api/windows/create/index.html new file mode 100644 index 0000000000..7673eadc83 --- /dev/null +++ b/files/zh-cn/mozilla/add-ons/webextensions/api/windows/create/index.html @@ -0,0 +1,169 @@ +--- +title: windows.create() +slug: Mozilla/Add-ons/WebExtensions/API/windows/create +translation_of: Mozilla/Add-ons/WebExtensions/API/windows/create +--- +<div>{{AddonSidebar()}}</div> + +<p>创建一个新的窗口.</p> + +<p>当你创建一个窗口时,你可以:</p> + +<ul> + <li>加载一个或多个新的标签到该窗口中.</li> + <li>将一个现有窗口的.标签移动到新的窗口中</li> + <li>设置窗口的大小和位置</li> + <li>创建一个面板样式的窗口,它没有浏览器的默认样式(地址栏,工具栏等)</li> + <li>设置窗口的多种属性, 像是获得焦点或是为隐私窗口.</li> +</ul> + +<p>这是一个异步的方法返回一个 <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></code>.</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox brush:js">var creating = browser.windows.create( + createData // optional object +) +</pre> + +<h3 id="参数">参数</h3> + +<dl> + <dt><code>createData</code>{{optional_inline}}</dt> + <dd><code>object</code>.</dd> + <dd> + <dl class="reference-values"> + <dt><code>url</code>{{optional_inline}}</dt> + <dd><code><code>字符串或字符串数组</code></code>. 一个URL或都URL数组要在该窗口中打开成标签页的. 完整的需要包括scheme (像. <code>http://www.google.com</code>, not <code>www.google.com</code>). 相对路径将相对于该拓展中的当前页. 默认为打开新标签页.</dd> + <dt><code>tabId</code>{{optional_inline}}</dt> + <dd><code>integer</code>. 如果设置了该值,将该tab从一个现有的窗口中移到新窗口中.</dd> + <dt><code>left</code>{{optional_inline}}</dt> + <dd><code>integer</code>. 窗口左边到屏幕左边缘的距离.如果没有设定,新窗口将按上一个焦点窗口定位水平位置. 对于panel样式窗口,该值不起作用.</dd> + <dt><code>top</code>{{optional_inline}}</dt> + <dd>窗口顶部到屏幕的顶部距离.如果没有设定,新窗口将按上一个焦点窗口定位垂直位置. 对于panel样式窗口,该值不起作用.</dd> + <dt><code>width</code>{{optional_inline}}</dt> + <dd><code>integer</code>. 新窗口的宽度, 包含框架. 未设定则使用默认宽度。.</dd> + <dt><code>height</code>{{optional_inline}}</dt> + <dd><code>integer</code>. 新窗口的高度, 包含框架. 未设定则使用默认高度。.</dd> + <dt><code>focused</code>{{optional_inline}}</dt> + <dd><code>boolean</code>.如果 为<code>true</code>, 新窗口将获取焦点. 否则新窗口当在后台打开并且当前焦点窗口继续保持焦点.。.默认为true</dd> + <dt><code>incognito</code>{{optional_inline}}</dt> + <dd><code>boolean</code>. 是否打开为一个隐私窗口. <code>如果设定为隐私窗口并且引入了tabId</code>, 则tabId对应的标签必须是一个隐私标签— 即不能把一个不是隐私标签的标签页移动到隐私窗口中。</dd> + <dt><code>type</code>{{optional_inline}}</dt> + <dd>一{{WebExtAPIRef('windows.CreateType')}} 值,表示创建窗口的类型. <code>panel</code> 或者<code>popup</code> 样式将打开一个没有默认浏览器样式的窗口 (地址栏,工具栏等)。</dd> + <dt><code>state</code>{{optional_inline}}</dt> + <dd>一个 {{WebExtAPIRef('windows.WindowState')}} 值, 窗口的祲状态。 最小化、最大化、全屏状态不能与<code>left</code>, <code>top</code>, <code>width</code>, or <code>height</code>属性一起使用。</dd> + </dl> + </dd> +</dl> + +<h3 id="返回值">返回值</h3> + +<p>一个 <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></code> 其中传入一个包含新窗口细节的 {{WebExtAPIRef('windows.Window')}} 对象。 这个{{WebExtAPIRef('windows.Window')}} 有自己的tabs属性集 ,而不像 {{WebExtAPIRef("windows.get()")}}返回的窗口对象和相似的API, 如果传递了populate项其仅仅包含tabs. 如果发生了错误 promise will be rejected with an error message.</p> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<p class="hidden">这个页面中的兼容性表是从结构化数据生成的。如果你想为数据,请参照 <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> 并且给我们发请求</p> + +<p>{{Compat("webextensions.api.windows.create", 10)}}</p> + +<h2 id="示例">示例</h2> + +<p>打开一个包含两个标签的窗口</p> + +<pre class="brush: js">function onCreated(windowInfo) { + console.log(`Created window: ${windowInfo.id}`); +} + +function onError(error) { + console.log(`Error: ${error}`); +} + +browser.browserAction.onClicked.addListener((tab) => { + var creating = browser.windows.create({ + url: ["https://developer.mozilla.org", + "https://addons.mozilla.org"] + }); + creating.then(onCreated, onError); +});</pre> + +<p>当用户点击一个browser action打开一个窗口,并且将当前活跃的标签移动其中</p> + +<pre class="brush: js">function onCreated(windowInfo) { + console.log(`Created window: ${windowInfo.id}`); +} + +function onError(error) { + console.log(`Error: ${error}`); +} + +browser.browserAction.onClicked.addListener((tab) => { + var creating = browser.windows.create({ + tabId: tab.id + }); + creating.then(onCreated, onError); +});</pre> + +<p>打开一个小面板样式的窗口,并且加载一个本地包中的文件到其中</p> + +<pre class="brush: js">function onCreated(windowInfo) { + console.log(`Created window: ${windowInfo.id}`); +} + +function onError(error) { + console.log(`Error: ${error}`); +} + +browser.browserAction.onClicked.addListener((tab) => { + + var popupURL = browser.extension.getURL("popup/popup.html"); + + var creating = browser.windows.create({ + url: popupURL, + type: "popup", + height: 200, + width: 200 + }); + creating.then(onCreated, onError); + +});</pre> + +<p>{{WebExtExamples}}</p> + +<div class="note"><strong>Acknowledgements</strong> + +<p>This API is based on Chromium's <a href="https://developer.chrome.com/extensions/windows#method-create"><code>chrome.windows</code></a> API. This documentation is derived from <a href="https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/windows.json"><code>windows.json</code></a> in the Chromium code.</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> + +<div class="hidden"> +<pre>// Copyright 2015 The Chromium Authors. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +</pre> +</div> diff --git a/files/zh-cn/mozilla/add-ons/webextensions/api/windows/index.html b/files/zh-cn/mozilla/add-ons/webextensions/api/windows/index.html new file mode 100644 index 0000000000..b923176e30 --- /dev/null +++ b/files/zh-cn/mozilla/add-ons/webextensions/api/windows/index.html @@ -0,0 +1,116 @@ +--- +title: windows +slug: Mozilla/Add-ons/WebExtensions/API/windows +translation_of: Mozilla/Add-ons/WebExtensions/API/windows +--- +<div>{{AddonSidebar}}</div> + +<p>与浏览器窗口互动。您可以使用此 API 获取有关已打开窗口的信息,以及打开、修改和关闭窗口。您也可以监听窗口的打开、关闭和其激活事件。</p> + +<h2 id="类型">类型</h2> + +<dl> + <dt>{{WebExtAPIRef("windows.WindowType")}}</dt> + <dd>浏览器窗口的类型。</dd> + <dt>{{WebExtAPIRef("windows.WindowState")}}</dt> + <dd>浏览器窗口的状态。</dd> + <dt>{{WebExtAPIRef("windows.Window")}}</dt> + <dd>有关一个浏览器窗口的信息。</dd> + <dt>{{WebExtAPIRef("windows.CreateType")}}</dt> + <dd>指定要创建的浏览器窗口的类型。</dd> +</dl> + +<h2 id="属性">属性</h2> + +<dl> + <dt>{{WebExtAPIRef("windows.WINDOW_ID_NONE")}}</dt> + <dd><code>windowId</code> 值表示不存在浏览器窗口。</dd> + <dt>{{WebExtAPIRef("windows.WINDOW_ID_CURRENT")}}</dt> + <dd><code>windowId</code> 值表示当前窗口。</dd> +</dl> + +<h2 id="函数">函数</h2> + +<dl> + <dt>{{WebExtAPIRef("windows.get()")}}</dt> + <dd>指定其 ID,获取一个窗口的细节。</dd> + <dt>{{WebExtAPIRef("windows.getCurrent()")}}</dt> + <dd>获取当前窗口。</dd> + <dt>{{WebExtAPIRef("windows.getLastFocused()")}}</dt> + <dd>获取最近获得焦点的窗口,通常它是“顶部”的窗口。</dd> + <dt>{{WebExtAPIRef("windows.getAll()")}}</dt> + <dd>获取所有窗口。</dd> + <dt>{{WebExtAPIRef("windows.create()")}}</dt> + <dd> + <p>创建新窗口。</p> + </dd> + <dt>{{WebExtAPIRef("windows.update()")}}</dt> + <dd>更新一个窗口的属性。使用此项对移动、调整大小、聚焦/取消聚焦等。</dd> + <dt>{{WebExtAPIRef("windows.remove()")}}</dt> + <dd>关闭一个窗口及其所有标签页。</dd> +</dl> + +<h2 id="事件">事件</h2> + +<dl> + <dt>{{WebExtAPIRef("windows.onCreated")}}</dt> + <dd>一个窗口创建时触发。</dd> + <dt>{{WebExtAPIRef("windows.onRemoved")}}</dt> + <dd>一个窗口关闭时触发。</dd> + <dt>{{WebExtAPIRef("windows.onFocusChanged")}}</dt> + <dd>当前有焦点的窗口改变时触发。</dd> +</dl> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<p>{{Compat("webextensions.api.windows")}}</p> + +<div class="hidden note"> +<p>Chrome 的不兼容 部分列在 <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>,为采用 <a href="/en-US/docs/Template:WebExtChromeCompat">WebExtChromeCompat</a> 宏。</p> + +<p>如果您需要更新此内容,编辑 <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>,然后按住Shift并刷新此页面以查看您的变更。</p> +</div> + +<h3 id="Edge_的不兼容">Edge 的不兼容</h3> + +<p>Edge 中不支持 Promises。需使用回调。</p> + +<p>{{WebExtExamples("h2")}}</p> + +<div class="note"><strong>声明</strong> + +<p>此 API 基于 Chromium 的 <a href="https://developer.chrome.com/extensions/windows"><code>chrome.windows</code></a> API。此文档基于 Chromium 代码中的<a href="https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/windows.json"><code> windows.json</code></a>。</p> + +<p>Microsoft Edge 兼容性数据由微软公司提供,并包含在创作共用 署名 3.0美国许可证下。</p> +</div> + +<div class="hidden"> +<pre>// Copyright 2015 The Chromium Authors. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +</pre> +</div> diff --git a/files/zh-cn/mozilla/add-ons/webextensions/api/windows/windowstate/index.html b/files/zh-cn/mozilla/add-ons/webextensions/api/windows/windowstate/index.html new file mode 100644 index 0000000000..605f2cf071 --- /dev/null +++ b/files/zh-cn/mozilla/add-ons/webextensions/api/windows/windowstate/index.html @@ -0,0 +1,66 @@ +--- +title: windows.WindowState +slug: Mozilla/Add-ons/WebExtensions/API/windows/WindowState +translation_of: Mozilla/Add-ons/WebExtensions/API/windows/WindowState +--- +<div>{{AddonSidebar()}}</div> + +<p>浏览器窗口的状态。</p> + +<h2 id="类型">类型</h2> + +<p>类型的值是字符串类型。 可能的值如下:</p> + +<ul> + <li><code>"normal"</code></li> + <li><code>"minimized"</code></li> + <li><code>"maximized"</code></li> + <li><code>"fullscreen"</code></li> + <li><code>"docked"</code></li> +</ul> + +<h2 id="浏览器适配">浏览器适配</h2> + +<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p> + +<p>{{Compat("webextensions.api.windows.WindowState")}}</p> + +<p>{{WebExtExamples}}</p> + +<div class="note"><strong>致谢</strong> + +<p>此API基于谷歌浏览器 <a href="https://developer.chrome.com/extensions/windows#type-WindowState"><code>chrome.windows</code></a> API。此文档源于谷歌源码 <a href="https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/windows.json"><code>windows.json</code></a> .</p> + +<p>微软Edge浏览器兼容性数据由微软公司提供,并包含在美国Creative Commons Attribution 3.0许可证下。</p> +</div> + +<div class="hidden"> +<pre>// Copyright 2015 The Chromium Authors. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +</pre> +</div> diff --git a/files/zh-cn/mozilla/add-ons/webextensions/api/windows/windowtype/index.html b/files/zh-cn/mozilla/add-ons/webextensions/api/windows/windowtype/index.html new file mode 100644 index 0000000000..6f9e5572b2 --- /dev/null +++ b/files/zh-cn/mozilla/add-ons/webextensions/api/windows/windowtype/index.html @@ -0,0 +1,65 @@ +--- +title: windows.WindowType +slug: Mozilla/Add-ons/WebExtensions/API/windows/WindowType +translation_of: Mozilla/Add-ons/WebExtensions/API/windows/WindowType +--- +<div>{{AddonSidebar()}}</div> + +<p>浏览器窗口的类型。</p> + +<h2 id="Type">Type</h2> + +<p>类型的值是字符串类型。 可能的值如下:</p> + +<ul> + <li><code>"normal"</code></li> + <li><code>"popup"</code></li> + <li><code>"panel"</code></li> + <li><code>"devtools"</code></li> +</ul> + +<h2 id="浏览器适配">浏览器适配</h2> + + + +<p>{{Compat("webextensions.api.windows.WindowType")}}</p> + +<p>{{WebExtExamples}}</p> + +<div class="note"><strong>Acknowledgements</strong> + +<p>This API is based on Chromium's <a href="https://developer.chrome.com/extensions/windows#type-WindowType"><code>chrome.windows</code></a> API. This documentation is derived from <a href="https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/windows.json"><code>windows.json</code></a> in the Chromium code.</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> + +<div class="hidden"> +<pre>// Copyright 2015 The Chromium Authors. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +</pre> +</div> |
