tabs.onMoved
当标签页在窗口内移动时触发。
仅会触发一次移动事件,用以代表用户直接移动了的标签页。不会为其他响应移动的标签页触发移动事件。此事件不会在标签页在窗口之间移动时触发。对于这种情况,请参阅 tabs.onDetached
。
语法
js
browser.tabs.onMoved.addListener(listener)
browser.tabs.onMoved.removeListener(listener)
browser.tabs.onMoved.hasListener(listener)
事件具有三个函数:
addListener(listener)
-
向此事件添加一个监听器。
removeListener(listener)
-
停止监听此事件。
listener
参数是要移除的监听器。 hasListener(listener)
-
检查
listener
是否已注册此事件。如果正在监听,则返回true
,否则返回false
。
addListener 语法
参数
附加对象
moveInfo
示例
监听并记录移动事件:
js
function handleMoved(tabId, moveInfo) {
console.log(
`标签页 ${tabId} 从 ${moveInfo.fromIndex} 移动至 ${moveInfo.toIndex}`,
);
}
browser.tabs.onMoved.addListener(handleMoved);
示例扩展
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | ||||||
---|---|---|---|---|---|---|---|
onMoved |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No 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
。