0

I am building a Firefox add-on. I have attached an event listener to links with a class. On link click I need to redirect the user to a different page (preferably separate tab) with some additional parameters added to it as query string. How can I achieve this from the addon? I tried setting location.href but it opens the target like a popup (I mean a window without any toolbar and menubar).

This is the function that gets triggered on lck event:

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);
4

2 回答 2

1

如果您需要在新选项卡中打开页面,那么您应该打开一个选项卡

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

请注意,我使用encodeURIComponent()函数来确保参数被正确编码。

于 2012-10-08T07:30:05.357 回答
0

你试过这个吗?

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

使用 Chrome、IE 或 FF 时,它适用于 chrome 中的扩展程序和任何普通页面

于 2012-10-08T07:32:37.883 回答