Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript, firefox addon, open new tab

I have an addon that open a html page when you click a button on the browser bar (so far so good) in the html page I have this javascript:

    function new_version_show_window()
        {
            if (prefManager.getCharPref("extensions.mf_unblocker.blocker_version_in_prefs") != this_version)
            {


                gBrowser.selectedTab = gBrowser.addTab("http://mfre.com/mf/new_install_'+this_version+'.html");    
            }
        }

But I am getting the error:

gBrowser is undefined

The javascript is in

chrome://mf_unblocker/content/0_register.html

so I am very much still in the browser extension how do i get it to open a new tab?

Thanks!
Ryan

like image 854
Ryan Avatar asked Dec 22 '22 11:12

Ryan


1 Answers

Try this:

var win = Components.classes['@mozilla.org/appshell/window-mediator;1']
                  .getService(Components.interfaces.nsIWindowMediator)
                  .getMostRecentWindow('navigator:browser');
                win.gBrowser.selectedTab = win.gBrowser.addTab(url);

Assuming url is the URL to be opened

like image 200
ysrb Avatar answered Dec 24 '22 02:12

ysrb