-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zh-CN: create
sidebarAction.isOpen()
(#24895)
Co-authored-by: A1lo <[email protected]>
- Loading branch information
1 parent
fa93834
commit cf546b2
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
files/zh-cn/mozilla/add-ons/webextensions/api/sidebaraction/isopen/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
title: sidebarAction.isOpen() | ||
slug: Mozilla/Add-ons/WebExtensions/API/sidebarAction/isOpen | ||
l10n: | ||
sourceCommit: 43e3ff826b7b755b05986c99ada75635c01c187c | ||
--- | ||
|
||
{{AddonSidebar}} | ||
|
||
在给定窗口中侧边栏打开的情况下返回 `true`。 | ||
|
||
此函数接受一个 `windowId` 作为参数: | ||
|
||
- 如果提供了 `windowId`,则函数将检查给定的浏览器窗口。 | ||
- 如果省略了 `windowId`,则函数将检查最顶层的浏览器窗口。 | ||
|
||
这是一个返回 [`Promise`](/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise) 的异步函数。 | ||
|
||
## 语法 | ||
|
||
```js-nolint | ||
let gettingIsOpen = browser.sidebarAction.isOpen( | ||
details // 对象 | ||
) | ||
``` | ||
|
||
### 参数 | ||
|
||
- `details` | ||
|
||
- : `object`。一个对象,可选地包含要检查的 `windowId` 属性。 | ||
|
||
- `windowId` {{optional_inline}} | ||
- : `integer`。要检查的浏览器窗口的 ID。如果省略,则默认为 {{WebExtAPIRef("windows.WINDOW_ID_CURRENT")}},它引用最顶层的浏览器窗口。 | ||
|
||
### 返回值 | ||
|
||
[`Promise`](/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise),如果给定窗口中的侧边栏打开,则兑现 `true`,否则兑现 `false`。 | ||
|
||
## 浏览器兼容性 | ||
|
||
{{Compat}} | ||
|
||
## 示例 | ||
|
||
检查最顶层的窗口: | ||
|
||
```js | ||
browser.sidebarAction.isOpen({}).then((result) => { | ||
console.log(result); | ||
}); | ||
``` | ||
|
||
检查所有打开的窗口: | ||
|
||
```js | ||
async function checkWindow(windowId) { | ||
const result = await browser.sidebarAction.isOpen({ windowId }); | ||
console.log(`窗口:${windowId} 状态:${result}`); | ||
} | ||
|
||
browser.windows.getAll().then((all) => { | ||
for (const { id } of all) { | ||
checkWindow(id); | ||
} | ||
}); | ||
``` | ||
|
||
{{WebExtExamples}} |