Thunderbird 扩展,加载事件似乎只发生一次
我正在尝试编写一个扩展来自动填充外发消息的主题行。
下面的代码似乎只执行一次。它链接到 chrome://messenger/content/messengercompose/messengercompose.xul 的覆盖层,当用户点击写入按钮撰写新消息时,该覆盖层会打开。我第一次单击“写入”并在“收件人”字段中输入文本时,主题行会自动填充。但是,如果我关闭“撰写”窗口并打开一个新窗口,则“收件人”字段中不会有已注册的事件侦听器。
var execute = {
onLoad: function(e){
alert("onload");
var addrTextbox = document.getElementById("addressCol2#1"); //"to" field
addrTextbox.addEventListener("change", execute.autoFillSubjectLine, false);
},
autoFillSubjectLine: function(e){
var msgSubject = document.getElementById("msgSubject");
msgSubject.value = "text goes here";
},
};
window.addEventListener("load", execute.onLoad, true);
在过去的四天里,我一直在试图解决这个问题,但就是无法解决。我对 javascript 和 DOM 没有太多的经验(主要是 java),所以我认为这对于你们中的一些专家来说可能很容易弄清楚。请帮忙。
I'm attempting to write an extension to autofill the subject line of an outgoing message.
The following code only seems to execute once. It's linked to an overlay of chrome://messenger/content/messengercompose/messengercompose.xul which opens when a user hits the write button to compose a new message. The first time I click write and enter text in the "to" field, the subject line gets autofilled. However, if I close the "compose" window and bring up a new one it will not have the registered event listener in the "to" field.
var execute = {
onLoad: function(e){
alert("onload");
var addrTextbox = document.getElementById("addressCol2#1"); //"to" field
addrTextbox.addEventListener("change", execute.autoFillSubjectLine, false);
},
autoFillSubjectLine: function(e){
var msgSubject = document.getElementById("msgSubject");
msgSubject.value = "text goes here";
},
};
window.addEventListener("load", execute.onLoad, true);
I have been trying to figure this out now for the past 4 days and just can't get it. I don't have all that much experience with javascript and the DOM, (mostly just java), so I'm thinking this might be rather easy for some of you guru folk to figure out. Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我已经开始工作了。我只花了大约一周的时间进行研究,但这不就是我们喜欢编码的原因吗?不管怎样,解决方案似乎是使用 gMsgCompose、状态侦听器和 compose-window-init 事件(而不是 load 事件)。所以就是这样。
Well, I got it to work. Only took me about a week of research, but isn't that why we love to code. Anyway, the solution seems to be the use of gMsgCompose, state listeners, and the
compose-window-init
event as opposed to theload
event. So here it is.