action.disable()
禁用某一标签页的浏览器操作——意味着当该标签页处于活动状态时,无法单击该按钮。
备注: 该 API 在 Manifest V3 或更高版本中可用。
语法
js
browser.action.disable(
tabId // 可选的整型值
)
参数
tabId
可选-
integer
,你希望禁用浏览器操作的标签页的 id。
示例
当点击后,禁用浏览器操作,并在每次打开新标签页时重新启用它:
js
browser.tabs.onCreated.addListener(() => {
browser.action.enable();
});
browser.action.onClicked.addListener(() => {
browser.action.disable();
});
仅对活动标签页禁用浏览器操作:
js
browser.action.onClicked.addListener((tab) => {
browser.action.disable(tab.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.
备注:
该 API 基于 Chromium 的 chrome.action
API。本文衍生自 Chromium 代码中的 browser_action.json
。