I am trying to open a new tab right next to the active tab in a firefox add-on. Here is my code:
var tabs = require("sdk/tabs");
tabs.open("http://www.google.com");
This opens the new tab at the end of the tab list. I couldn't figure out how to force it to position the new tab immediately after the active tab.
Get the index of the current tab, then set the index of the new tab to that + 1
var tabs = require("sdk/tabs");
var index = tabs.activeTab.index;
tabs.open("http://www.google.com");
tabs.activeTab.index = index + 1;
Alternatively, if you look at the docs, you'll see that there's a constructor parameter called
inBackground: boolean. If present and true, the new tab will be opened to the right of the active tab and will not be active.
By combining this with the onOpen event, you can achieve the desired effect:
var tabs = require("sdk/tabs");
tabs.open({
url: "http://www.google.com",
inBackground: true,
onOpen: function(tab) {
tab.activate();
}
});
I haven't tested either of these, so some debugging might be needed.