Firefox 扩展无法覆盖元素事件
我在尝试覆盖表单元素的 onsubmit
事件时遇到问题。我使用 addEventListener
添加监听器没有问题,但对于我的特殊情况,我需要替换 onsubmit,但由于某种原因,当我这样做时,它给了我这个错误:
Error: Component is not available = NS_ERROR_NOT_AVAILABLE
我的代码很简单:
gBrowser.contentDocument.getElementById("theform").onsubmit = function() {
return false;
};
本质上我想阻止表单提交,但是此代码失败并引发上述错误。使用 addEventListener
返回 false
似乎并没有阻止表单提交。
谢谢。
I'm having trouble trying to override a form element's onsubmit
event. I have no problem adding a listener with addEventListener
, but for my particular case, I need to replace the onsubmit but for some reason when I do, it gives me this error:
Error: Component is not available = NS_ERROR_NOT_AVAILABLE
My code is simply this:
gBrowser.contentDocument.getElementById("theform").onsubmit = function() {
return false;
};
Essentially I want to prevent the form from submitting, but this code fails and throws the above error. Using addEventListener
to return false
doesn't seem to stop the form from submitting.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
出于安全原因,扩展中的
getElementById
返回的对象是 DOM 元素周围的XPCNativeWrapper
;它不是元素本身。这导致了一些重要的限制。更多详细信息请参见此处:For security reasons, the object returned by
getElementById
in an extension is anXPCNativeWrapper
around the DOM element; it's not the element itself. This results in some important limitations. More details here: