打开"活动选项卡旁边的选项卡

Joh*_*ell 5 google-chrome-extension

对于我的Chrome扩展程序,我需要在活动/当前选项卡旁边打开一个新选项卡.但是tab.create方法总是将选项卡附加到选项卡列表的末尾.

Firefox具有relatedToCurrent设置标签位置的属性.

在活动标签旁边打开标签是否有Chrome等价物?

Yoi*_*aka 7

您可以使用"index"属性指定调用chrome.tabs.create()函数的位置.如果要在当前选项卡旁边打开新选项卡:

chrome.tabs.query({
    active: true, currentWindow: true
  }, tabs => {
    let index = tabs[0].index;
    chrome.tabs.create({
      ...,
      index: index + 1,
      ...
    }, tab => {
      ...
    });
  }
);
Run Code Online (Sandbox Code Playgroud)

  • `chrome.tabs.getCurrent`不返回当前活动的选项卡.你应该使用`chrome.tabs.query({active:true},...)`. (2认同)