Firefox 插件:“promptService” Mozilla 自己的示例代码不起作用
我使用 Mozilla Addon Builder 创建了一个扩展,该扩展创建了一个工具栏按钮。没有对代码进行任何更改,该代码在当前稳定的 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);
工具栏按钮出现,但单击时(我理解应该触发 onToolbarButtonCommand)它什么也不做。我对这里的调试有点模糊:这是我第一次尝试一种“hello world”不起作用的语言!
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 understand 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信,
onLoad
中的this
实际上不会指向您的对象。如果这是未经修改的代码,请提交有关错误它(我已经为您选择了正确的组件),它应该会很快得到修复。this
inonLoad
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.