开发者

Firefox loadURI not working

开发者 https://www.devze.com 2023-03-11 12:58 出处:网络
I have this code in the XUL file of a custom Firefox e开发者_StackOverflowxtension: <toolbarbutton label=\"Home\" id=\"home-b\"

I have this code in the XUL file of a custom Firefox e开发者_StackOverflowxtension:

<toolbarbutton label="Home" id="home-b"
               class="toolbarbutton-1 custombutton" 
               oncommand="getBrowserWindow().gBrowser.loadURI('http://www.google.com');" />

which is supposed to change the url to google.com. However, it's not working; nothing happens when I click on the button.

What did I do wrong?


Generally it is a good idea to open Error Console (Ctrl-Shift-J) and to check whether your code resulted in an error. The error message should give you a good idea about what's wrong.

That said, the error message is most likely "getBrowserWindow is not a function" - Firefox doesn't define a function like that. Your toolbar button is located in the browser window, so you don't need anything special to locate the window. This should do:

window.gBrowser.loadURI('http://www.google.com');

Note that this will load the page into the current tab. To open a new tab use:

window.gBrowser.loadOneTab('http://www.google.com');

See https://developer.mozilla.org/en/XUL/Method/loadOneTab for additional parameters of this method.

0

精彩评论

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