2012-10-08 15 views
0

我正在構建一個Firefox附加組件。我將一個事件監聽器附加到了一個類的鏈接上。在鏈接點擊我需要重定向用戶到不同的頁面(最好是單獨的選項卡)與一些額外的參數作爲查詢字符串添加到它。我怎樣才能從插件中實現這一點?我嘗試設置location.href,但它像彈出式窗口(我的意思是沒有任何工具欄和菜單欄的窗口)打開目標。如何從Firefox插件代碼重定向?

這是大幹快上LCK事件觸發的功能:

var myExtension = { 
init: function() { 
    // The event can be DOMContentLoaded, pageshow, pagehide, load or unload. 
    if(gBrowser) gBrowser.addEventListener("DOMContentLoaded", this.onPageLoad, false); 
}, 
onPageLoad: function(aEvent) { 
    var doc = aEvent.originalTarget; // doc is document that triggered the event 
    var win = doc.defaultView; // win is the window for the doc 
    // test desired conditions and do something 
    // if (doc.nodeName == "#document") return; // only documents 
    // if (win != win.top) return; //only top window. 
    // if (win.frameElement) return; // skip iframes/frames 
//  alert("page is loaded \n" +doc.location.href); 
     function toFb() 
     { 
      var Ele2=doc.getElementsByClassName('js-action-reply')[0].parentNode.parentNode.parentNode.parentNode.children[1]; 
      doc.location.href="http://www.lendingstream.co.uk/?txt="+Ele2.innerHTML; 
     } 
} 
} 
window.addEventListener("load", function load(event){ 
window.removeEventListener("load", load, false); //remove listener, no longer needed 
myExtension.init(); 
},false); 
+0

'doc.location.href'絕對不會打開任何彈出窗口 - 它改變的位置文件。代碼示例中的「doc」是什麼? –

+0

@WladimirPalant發佈了完整的代碼... pls chk –

回答

1

如果您需要在新標籤中打開一個頁面,那麼你應該open a tab

gBrowser.addTab("http://www.lendingstream.co.uk/?txt=" + encodeURIComponent(Ele2.innerHTML)); 

請注意,我用encodeURIComponent() function確保參數編碼正確。

0

你試過嗎?

window.open('http://www.lendingstream.co.uk/?txt='+Ele2.innerHTML); 

它使用Chrome,IE,或者當從工作擴展在Chrome和任何正常頁面FF