开发者

Firefox Addon: 'promptService' doesn't work from Mozilla's own sample code

I've created an extension using the Mozilla Addon Builder that creates a toolbar button. No changes have been made to the code, which is running in the current stable FF 3.

var mytestextension = {
  onLoad: function() {
    // initialization code
    this.initialized = true;
    this.strings = document.getElementById("mytestextension-strings");
  },

  onMenuItemCommand: function(e) {
    var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
                                  .getService(Components.interfaces.nsIPromptService);
    promptService.alert(window, this.strings.getString("helloMessageTitle"),
                                this.strings.getString("helloMessage"));
  },

  onToolbarButtonCommand: function(e) {
    // just reuse the function above.  you can change this, obviously!
    mytestextension.onMenuItemCommand(e);
  }
};

window.addEventListener("load", mytestextension.onLoad, false);

The toolbar button appears, but on click (which I un开发者_StackOverflow社区derstand should trigger onToolbarButtonCommand) it does nothing. I'm a little vague about debugging here: it's the first time I've tried a language where the 'hello world' hasn't worked!


this in onLoad isn't actually going to be pointing to your object, I believe. If this is unmodified code, please file a bug about it (I've already selected the right component for you), and it should get fixed quickly.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜