如何使用附加组件打开新选项卡



我需要firefox浏览器打开一个新选项卡。但下面的代码打开新窗口。

window.addEventListener('click', function(event) {
    var doc = event.originalTarget;
    var origEl = event.target || event.srcElement;
    if(origEl.tagName === 'A' || origEl.tagName === 'a') {
        tabs[0]=window.open("http://giaiphapthuonghieu.vn","http://giaiphapthuonghieu.vn");
    }
}, false);

这样做:var tab = gBrowser.loadOneTab('http://giaiphapthuonghieu.vn', {referrerURI: Services.io.newURI('http://giaiphapthuonghieu.vn', null, null)});

所以你的代码应该是这样的:
window.addEventListener('click', function(event) {
    var doc = event.originalTarget;
    var origEl = event.target || event.srcElement;
    if(origEl.tagName === 'A' || origEl.tagName === 'a') {
        tabs[0] = gBrowser.loadOneTab('http://giaiphapthuonghieu.vn', {referrerURI: Services.io.newURI('http://giaiphapthuonghieu.vn', null, null)});
    }
}, false);

您可以在window.open中一次只给出一个url,并使用_blank在新选项卡中打开而不是窗口

tabs[0]=window.open("http://giaiphapthuonghieu.vn" '_blank');
tabs[0].focus();//to focus tab

相关内容

最新更新