Thought i would try to build and extension for firefox so I used the Add-on Builder to build a basic extension at MDC. When I click 开发者_开发百科the extension in the Tools menu it is ment to bring up a hello world popup, but it doesn't.
I think its the onLoad function fails to fetch the data from nigol-strings. But if its a generated code from the MDC website why does it have errors or is it me?
var nigol = {
onLoad: function() {
// initialization code
this.initialized = true;
this.strings = document.getElementById("nigol-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"));
}
};
window.addEventListener("load", nigol.onLoad, false);
Like i said I downloaded from the addon builder and have not made any alterations.
Thanks
The way you're calling onLoad
, the value of this
in that function is not what you think it is. Try this instead:
window.addEventListener("load", function() { nigol.onLoad(); }, false);
精彩评论