tabs.moveInSuccession() 编辑

Modifies the succession relationship for a group of tabs.

Using the tabs API, a tab can be assigned a successor tab in the same window. If tab B is the successor of tab A, and tab A is closed while it is the active tab, tab B will be activated next. If tab A doesn't have a successor, then the browser is free to determine which tab to activate next. If tab B is the successor of tab A, then tab A is called a predecessor of tab B. A tab can have at most one successor, but it can have any number of predecessors. A tab cannot take itself or a tab in a different window as a successor.

All tabs start out with no successor; tabs only get a successor if assigned one by a WebExtension. However, the browser must not orphan a tab in a succession relationship with other tabs, if possible: if tab B is the successor of tab A, and tab C is the successor of tab B, and B is closed (or moved to another window), then tab A will take tab C as its successor. Preventing C from being orphaned in this way is called moving a tab (B) from its line of succession.

tabs.moveInSuccession() takes an array of tab IDs, and moves all of those tabs from their lines of succession. It then makes each tab the successor of the previous tab in the array, forming a chain. It can optionally set the successor of the last tab in the chain to an anchor tab, which is not moved from its line of succession. Additional options can control whether the tab chain is "prepended" or "appended" to the anchor tab, and whether the operation acts like a linked-list insert.

While the successor tab can be assigned with tabs.update(), it is often desirable to use tabs.moveInSuccession() to change successors, even if only a single tab is having its successor assigned. The difference is that browser.tabs.moveInSuccession([a], b) moves tab a from its line of succession, so any predecessors of a will adopt a's previous successor; whereas if browser.tabs.update(a, {successorTabId: b}) is used instead, tab a may continue to be the successor of other tabs, which could be unexpected. Another advantage of tabs.moveInSuccession() is that all of the succession changes happen atomically, without having to worry about races between calls to tabs.update() and tabs.get() and other operations like the user closing a tab.

Syntax

browser.tabs.moveInSuccession([1, 3, 5, 7, 2, 9], 4, {insert:true})

Parameters

tabIds
array of integer. An array of tab IDs. The order of the elements in the array defines the relationship of the tabs. Any invalid tab IDs, or tab IDs corresponding to tabs not in the same window as tabId (or the first tab in the array, if tabId is omitted), will be ignored—they will keep their current successors and predecessors.
tabId Optional
integer. The ID of the tab that will be the successor of the last tab in the tabIds array. If this ID is invalid or tabs.TAB_ID_NONE, the last tab will not have a successor. Defaults to tabs.TAB_ID_NONE.
options Optional
object.
append Optional
boolean. Determines whether to move the tabs in tabIds before or after tabIdin the succession. If false, the tabs are moved before tabId, if true, the tabs are moved after tabId. Defaults to false.
insert Optional
boolean. Determines whether to link up the current predecessors or successor (depending on options.append) of tabId to the other side of the chain after it is prepended or appended. If true, one of the following happens: if options.append is false, the first tab in the array is set as the successor of any current predecessors of tabId; if options.append is true, the current successor of tabId is set as the successor of the last tab in the array. Defaults to false.

Browser compatibility

BCD tables only load in the browser

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:39 次

字数:5678

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文