tabs.remove()
关闭一个或多个标签页。
这是一个返回 Promise
的异步函数。
语法
js
let removing = browser.tabs.remove(
tabIds, // 整数或整数数组
);
参数
tabIds
-
integer
或integer
数组。要关闭的标签页的 ID。
返回值
一个 Promise
,当所有指定的标签页已被关闭或其 beforeunload
提示已被处理时其会被兑现且不带有参数。如果发生任何错误,promise 会以错误信息拒绝。
示例
关闭单个标签页:
js
function onRemoved() {
console.log(`已移除`);
}
function onError(error) {
console.log(`发生错误:${error}`);
}
let removing = browser.tabs.remove(2);
removing.then(onRemoved, onError);
关闭多个标签页:
js
function onRemoved() {
console.log(`已移除`);
}
function onError(error) {
console.log(`发生错误:${error}`);
}
let removing = browser.tabs.remove([15, 14, 1]);
removing.then(onRemoved, onError);
示例扩展
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | ||||||
---|---|---|---|---|---|---|---|
remove |
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.tabs
API。本文档源自 Chromium 代码中的 tabs.json
。