I have a simple list of research links on a Chrome Extension:
Research Link 1
Yes, there is an option for create:
chrome.tabs.create({url: 'http://www.google.com', active: false});
I'm using it in one of my extensions exactly as you described.
Here is what I ended up doing to allow a proper ctrl+click (open tab in new background window) in a Chrome Extension - uses jQuery.
<a class="ctrllink" style="cursor: pointer;" url="http://www.example1.com">Research Link 1</a>
<a class="ctrllink" style="cursor: pointer;" url="http://www.example2.com">Research Link 2</a>
<a class="ctrllink" style="cursor: pointer;" url="http://www.example3.com">Research Link 3</a>
I used the <a>
tag in order to maintain the default hyperlink style (color, hover underline, etc) but removed the href. Since there is no href, need to define the cursor style in the element or class.
Global variable:
var tabplacement = 0;
Tabplacement was done to simulate the way Chrome opens tabs, incrementing from the last created.
$(function () {
$('.ctrllink').on('click', function (event) {
var ctrlpressed = (event.ctrlKey || event.metaKey);
var url = $(this).attr('url');
chrome.tabs.getSelected(null, function (tab) {
tabplacement += 1;
var index = tab.index + tabplacement;
chrome.tabs.create({'url': url, active: !ctrlpressed, 'index': index});
});
});
});
Included the metaKey to handle Mac Command ⌘