browserAction.disable()
禁用选项卡中的浏览器操作,这意味着当该选项卡处于活动状态时,它无法被点击。
语法
js
browser.browserAction.disable(
tabId // 可选整数
)
参数
- tabId 可选
-
integer
。你想要禁用浏览器操作的选项卡的 ID。
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | ||||||
---|---|---|---|---|---|---|---|
disable |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
示例
点击时禁用浏览器操作,并在每次打开新选项卡时重新启用它:
js
browser.tabs.onCreated.addListener(() => {
browser.browserAction.enable();
});
browser.browserAction.onClicked.addListener(() => {
browser.browserAction.disable();
});
仅为活动选项卡禁用浏览器操作:
js
browser.browserAction.onClicked.addListener((tab) => {
browser.browserAction.disable(tab.id);
});
备注:
此 API 基于 Chromium 的 chrome.browserAction
API。该文档衍生自 Chromium 代码中的 browser_action.json
。