JavaScript/Chrome 扩展在第二个插槽中打开新标签

JavaScript/Chrome Extension Opening a New Tab In The Second Slot

我想创建一个功能,例如在 google chrome 的第二个插槽中打开一个新选项卡。我一直在使用手册,所以我不确定确切的错误是什么。例如,如果打开了五个选项卡,我希望新选项卡在原来的第一个和第二个选项卡之间打开。

  var newURL = "http://google.com/";
  chrome.tabs.create({url: newURL, tabId: 2});

您需要在选项参数中传递 index 才能在特定位置创建新标签页。

示例:

var newURL = "http://google.com/";
// Starts at 0. Therefore the new tab will be created in the second position
chrome.tabs.create({url: newURL, index: 1});

参考:https://developer.chrome.com/docs/extensions/reference/tabs/#method-create