我正在尝试在 Firefox 附加组件的事件选项卡旁边打开一个新选项卡。这是我的代码:
var tabs = require("sdk/tabs");
tabs.open("http://www.google.com");
这将在选项卡列表的末尾打开新选项卡。我不知道如何强制它在事件选项卡之后立即放置新选项卡。
最佳答案
获取当前标签页的索引,然后将新标签页的索引设置为那个+1
var tabs = require("sdk/tabs");
var index = tabs.activeTab.index;
tabs.open("http://www.google.com");
tabs.activeTab.index = index + 1;
或者,如果您查看 the docs ,你会看到有一个构造函数参数叫做
inBackground: boolean. If present and true, the new tab will be opened to the right of the active tab and will not be active.
将它与onOpen事件结合起来,就可以达到预期的效果:
var tabs = require("sdk/tabs");
tabs.open({
url: "http://www.google.com",
inBackground: true,
onOpen: function(tab) {
tab.activate();
}
});
我还没有测试过其中任何一个,因此可能需要进行一些调试。
关于firefox - 在 Firefox 附加 SDK 中打开事件选项卡旁边的选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25861762/