简体   繁体   English

JavaScript/Chrome 扩展在第二个插槽中打开一个新选项卡

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

I would like to make a function to open a new tab in the second slot of google chrome for instance.例如,我想做一个 function 在谷歌浏览器的第二个插槽中打开一个新标签。 I have been using the manual so I am unsure what the exact mistake is.我一直在使用手册,所以我不确定确切的错误是什么。 For instance, if there are five tabs open, I want the new tab to open between the original first and second ones.例如,如果打开了五个选项卡,我希望新选项卡在原来的第一个和第二个选项卡之间打开。

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

You will need to pass the index in your options argument in order to create a new tab at a specific position.您需要在选项参数中传递index ,以便在特定 position 处创建新选项卡。

Example:例子:

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});

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 打开新标签页后,Chrome扩展程序退出运行JavaScript - Chrome extension quits running javascript after opening new tab Chrome扩展程序:未在新标签页中打开URL - Chrome Extension: URL not opening in new tab 在 Google Chrome 扩展程序上打开一个新标签 - Opening a new tab on Google Chrome Extension Chrome 扩展:webRequest 重定向到现有选项卡,无需打开新选项卡 - Chrome Extension: webRequest Redirect to Existing Tab, Without Opening New Tab 从Chrome扩展程序的文本输入中打开新标签页 - Opening a new tab from text entry from chrome extension 如何测试使用Jasmine在Chrome扩展程序中打开新标签页? - How to test opening new tab with Jasmine in Chrome extension? 如何在不打开新标签的情况下在Google Chrome扩展程序中下载文件 - How to download file in google chrome extension without opening a new tab 使用Chrome扩展程序从活动标签页中的链接元素打开带有URL的新标签页 - Opening new tab with URL from link element in active tab using Chrome Extension 当使用window.open打开新标签页(自Chrome 45起)时,Chrome扩展程序内容脚本范围是否共享? - Is Chrome extension Content Script scope shared when opening a new tab with window.open (since Chrome 45)? 在Chrome扩展程序中打开新标签页 - Open a new tab in a Chrome extension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM