开发者

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜