最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript, firefox addon, open new tab - Stack Overflow

matteradmin9PV0评论

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("'+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

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./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

Share Improve this question asked Jul 14, 2011 at 23:45 RyanRyan 10k23 gold badges68 silver badges103 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

Try this:

var win = Components.classes['@mozilla/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

Post a comment

comment list (0)

  1. No comments so far