Opening a URL in current tab/window from a Firefox Extension

后端 未结 4 1698
生来不讨喜
生来不讨喜 2021-02-04 09:26

I am creating a Firefox Extension...what would be the javascript to open a URL in the current tab from a menuitem?

e.g. in my overlay.xul file i have the following line:

4条回答
  •  孤独总比滥情好
    2021-02-04 09:47

    Call this JS functions on your commmand

    //open a url current window:
    function openUrl(url) {
    content.wrappedJSObject.location = url;
    newTabBrowser = gBrowser.selectedBrowser;
    newTabBrowser.addEventListener("load", highlight, true);
    }
    
    //new tab
    function openUrlNewTab(url) {
    var win = Components.classes['@mozilla.org/appshell/window-mediator;1']
                .getService(Components.interfaces.nsIWindowMediator)
                .getMostRecentWindow('navigator:browser');
    win.gBrowser.selectedTab = win.gBrowser.addTab(url);
    }
    

提交回复
热议问题