Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zh-CN: create sidebarAction.close() #24896

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: sidebarAction.close()
slug: Mozilla/Add-ons/WebExtensions/API/sidebarAction/close
l10n:
sourceCommit: 43e3ff826b7b755b05986c99ada75635c01c187c
---

{{AddonSidebar}}

如果侧边栏是扩展自己的侧边栏,则关闭活动窗口中的侧边栏。

你只能在[用户操作](/zh-CN/docs/Mozilla/Add-ons/WebExtensions/User_actions)的处理程序内部调用此函数。

这是一个异步函数,返回一个 [`Promise`](/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise)。

## 语法

```js-nolint
browser.sidebarAction.close()
```

### 参数

无。

### 返回值

一个不以任何参数兑现的 [`Promise`](/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise)。

## 浏览器兼容性

{{Compat}}

## 示例

当用户选择上下文菜单项时关闭侧边栏:

```js
browser.menus.create({
id: "close-sidebar",
title: "关闭侧边栏",
contexts: ["all"],
});

browser.menus.onClicked.addListener(() => {
browser.sidebarAction.close();
});
```

{{WebExtExamples}}