aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/mozilla/add-ons/webextensions/api/tabs/query
diff options
context:
space:
mode:
authorFlorian Merz <me@fiji-flo.de>2021-02-11 12:56:40 +0100
committerFlorian Merz <me@fiji-flo.de>2021-02-11 12:56:40 +0100
commit310fd066e91f454b990372ffa30e803cc8120975 (patch)
treed5d900deb656a5da18e0b60d00f0db73f3a2e88e /files/zh-cn/mozilla/add-ons/webextensions/api/tabs/query
parent8260a606c143e6b55a467edf017a56bdcd6cba7e (diff)
downloadtranslated-content-310fd066e91f454b990372ffa30e803cc8120975.tar.gz
translated-content-310fd066e91f454b990372ffa30e803cc8120975.tar.bz2
translated-content-310fd066e91f454b990372ffa30e803cc8120975.zip
unslug zh-cn: move
Diffstat (limited to 'files/zh-cn/mozilla/add-ons/webextensions/api/tabs/query')
-rw-r--r--files/zh-cn/mozilla/add-ons/webextensions/api/tabs/query/index.html179
1 files changed, 179 insertions, 0 deletions
diff --git a/files/zh-cn/mozilla/add-ons/webextensions/api/tabs/query/index.html b/files/zh-cn/mozilla/add-ons/webextensions/api/tabs/query/index.html
new file mode 100644
index 0000000000..9afe6e80a8
--- /dev/null
+++ b/files/zh-cn/mozilla/add-ons/webextensions/api/tabs/query/index.html
@@ -0,0 +1,179 @@
+---
+title: 选项卡. 查询 ()
+slug: Mozilla/Add-ons/WebExtensions/API/tabs/查询
+translation_of: Mozilla/Add-ons/WebExtensions/API/tabs/query
+---
+<div>[阿登侧边栏()]</div>
+
+<p>获取具有指定属性的所有选项卡,如果未指定任何属性,则获取所有选项卡。</p>
+
+<p><font>这是返回 的异步函数。</font><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 notranslate">let querying = browser.tabs.query(<var>queryObj</var>)
+</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt><code><var>queryObj</var></code></dt>
+ <dd>
+ <p><code>object</code><font>.函数将仅获取其属性与此处包含的属性匹配的选项卡。</font><code>query()</code></p>
+
+ <p>请参阅 \WebExtAPIRef("选项卡")。Tab")=文档以了解有关这些属性的详细信息。</p>
+
+ <dl class="reference-values">
+ <dt><code>active</code><font>[optional_inline]</font></dt>
+ <dd><code>boolean</code><font>.选项卡是否在窗口中处于活动状态。</font></dd>
+ <dt><code>audible</code><font>[optional_inline]</font></dt>
+ <dd><code>boolean</code><font>.标签是否可听见。</font></dd>
+ <dt><code>autoDiscardable</code><font>[optional_inline]</font></dt>
+ <dd><code>boolean</code><font>.当资源不足时,浏览器是否可以自动丢弃选项卡。</font></dd>
+ <dt><code>cookieStoreId</code><font>[optional_inline]</font></dt>
+ <dd><code>string</code><font>.使用此仅返回其 Cookie 存储 ID 为 的选项卡。此选项仅在加载项具有权限时<a href="https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions">才可用</a>。</font><code>cookieStoreId</code><code>"cookies"</code></dd>
+ <dt><code>currentWindow</code><font>[optional_inline]</font></dt>
+ <dd><code>boolean</code><font>.选项卡是否在当前窗口中。</font></dd>
+ <dt><code>discarded</code><font>[optional_inline]</font></dt>
+ <dd><code>boolean</code><font>.是否丢弃选项卡。丢弃的选项卡是其内容已从内存中卸载,但仍在选项卡条中可见的选项卡。下次激活时,其内容将重新加载。</font></dd>
+ <dt><code>hidden</code><font>[optional_inline]</font></dt>
+ <dd><code>boolean</code><font>.选项卡是否隐藏。</font></dd>
+ <dt><code>highlighted</code><font>[optional_inline]</font></dt>
+ <dd><code>boolean</code><font>.选项卡是否突出显示。</font></dd>
+ <dt><code>index</code><font>[optional_inline]</font></dt>
+ <dd><code>integer</code><font>.选项卡在其窗口中的位置。</font></dd>
+ <dt><code>muted</code><font>[optional_inline]</font></dt>
+ <dd><code>boolean</code><font>.选项卡是否为静音。</font></dd>
+ <dt><code>lastFocusedWindow</code><font>[optional_inline]</font></dt>
+ <dd><code>boolean</code><font>.选项卡是否在上一个焦点窗口中。</font></dd>
+ <dt><code>pinned</code><font>[optional_inline]</font></dt>
+ <dd><code>boolean</code><font>.选项卡是否固定。</font></dd>
+ <dt><code>status</code><font>[optional_inline]</font></dt>
+ <dd>{WebExtAPIRef('选项卡。TabStatus ')=。选项卡是否已完成加载。</dd>
+ <dt><code>title</code><font>[optional_inline]</font></dt>
+ <dd><code>string</code><font>.将页面标题与图案匹配。</font></dd>
+ <dt><code>url</code><font>[optional_inline]</font></dt>
+ <dd><code><code>string</code></code><font>或。将选项卡与一个或多个匹配<a href="/en-US/docs/Mozilla/Add-ons/WebExtensions/Match_patterns">模式匹配</a>。请注意,片段标识符不匹配。</font><code><code>array</code> of <code><code>string</code></code></code></dd>
+ <dt><code>windowId</code><font>{{optional_inline}}</font></dt>
+ <dd><code>integer</code><font>. The of the parent window, or {{WebExtAPIRef('windows.WINDOW_ID_CURRENT')}} for the current window.</font><code>id</code></dd>
+ <dt><code>windowType</code><font>{{optional_inline}}</font></dt>
+ <dd>{{WebExtAPIRef('tabs.WindowType')}}. The type of window the tabs are in.</dd>
+ </dl>
+ </dd>
+</dl>
+
+<h3 id="Return_value">Return value</h3>
+
+<p><font>A that will be fulfilled with an of objects, containing information about each matching tab.</font><code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></code><code>array</code><code>{{WebExtAPIRef('tabs.Tab')}}</code></p>
+
+<p>If any error occurs, the promise will be rejected with an error message.</p>
+
+<h2 id="Examples">Examples</h2>
+
+<p>Get all tabs:</p>
+
+<pre class="brush: js notranslate">function logTabs(tabs) {
+ for (let tab of tabs) {
+ // tab.url requires the `tabs` permission
+ console.log(tab.url);
+ }
+}
+
+function onError(error) {
+ console.log(`Error: ${error}`);
+}
+
+let querying = browser.tabs.query({});
+querying.then(logTabs, onError);</pre>
+
+<p>Get all tabs in the current window:</p>
+
+<pre class="brush: js notranslate">function logTabs(tabs) {
+ for (let tab of tabs) {
+ // tab.url requires the `tabs` permission
+ console.log(tab.url);
+ }
+}
+
+function onError(error) {
+ console.log(`Error: ${error}`);
+}
+
+let querying = browser.tabs.query({currentWindow: true});
+querying.then(logTabs, onError);</pre>
+
+<p>Get the active tab in the current window:</p>
+
+<pre class="brush: js notranslate">function logTabs(tabs) {
+ // tabs[0].url requires the `tabs` permission
+ console.log(tabs[0].url);
+}
+
+function onError(error) {
+ console.log(`Error: ${error}`);
+}
+
+let querying = browser.tabs.query({currentWindow: true, active: true});
+querying.then(logTabs, onError);</pre>
+
+<p><font>Get tabs for all HTTP and HTTPS URLs under or any of its subdomains:</font><code>"mozilla.org"</code></p>
+
+<pre class="brush: js notranslate">function logTabs(tabs) {
+ for (let tab of tabs) {
+ // tab.url requires the `tabs` permission
+ console.log(tab.url);
+ }
+}
+
+function onError(error) {
+ console.log(`Error: ${error}`);
+}
+
+let querying = browser.tabs.query({url: "*://*.mozilla.org/*"});
+querying.then(logTabs, onError);</pre>
+
+<p>{{WebExtExamples}}</p>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+
+
+<p>{{Compat("webextensions.api.tabs.query")}}</p>
+
+<div class="note"><strong>Acknowledgements</strong>
+
+<p>This API is based on Chromium's <a href="https://developer.chrome.com/extensions/tabs#method-query"><code>chrome.tabs</code></a> API. This documentation is derived from <a href="https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/tabs.json"><code>tabs.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 class="notranslate">// 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>