tabs.onAttached
当标签页附加到窗口时触发,例如因为它在窗口之间移动。
语法
js
browser.tabs.onAttached.addListener(listener)
browser.tabs.onAttached.removeListener(listener)
browser.tabs.onAttached.hasListener(listener)
事件具有三个函数:
addListener(listener)
-
向此事件添加一个监听器。
removeListener(listener)
-
停止监听此事件。
listener
参数是要移除的监听器。 hasListener(listener)
-
检查
listener
是否已注册此事件。如果正在监听,则返回true
,否则返回false
。
addListener 语法
参数
listener
-
此事件发生时调用的函数。该函数接收以下参数:
tabId
-
integer
。附加到新窗口的标签页的 ID。 attachInfo
-
object
。新窗口的 ID 以及标签页在其中的位置。详见 attachInfo 部分。
附加对象
attachInfo
newWindowId
-
integer
。新窗口的 ID。 newPosition
-
integer
。标签页在新窗口中的索引位置。
示例
监听 attach 事件并记录信息:
js
function handleAttached(tabId, attachInfo) {
console.log(`标签页:${tabId} 已附加`);
console.log(`新窗口:${attachInfo.newWindowId}`);
console.log(`新索引:${attachInfo.newPosition}`);
}
browser.tabs.onAttached.addListener(handleAttached);
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | ||||||
---|---|---|---|---|---|---|---|
onAttached |
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
。