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の拡張機能から、およびChrome、IE、またはFFを使用している場合は通常のページから機能します

于 2012-10-08T07:32:37.883 に答える