Chrome 用户脚本 (Greasemonkey) - 阻止 Gmail 发送电子邮件
我正在编写一个 Chrome 用户脚本 (Greasemonkey) 扩展,以便在用户单击 Gmail 的“发送”按钮(在撰写窗口等中)时显示确认对话框。
我已经成功地附加到按钮的点击,并在点击按钮时显示一个对话框,方法是:
addEventListener("click", function(e) { ......... }, true);
但我无法阻止电子邮件的发送。我尝试过使用:
e.stopPropagation();
e.preventDefault();
return false;
如何阻止 Gmail 发送电子邮件?
I am writing a Chrome Userscript (Greasemonkey) extension to display a confirmation dialog when the user clicks on Gmail's Send button (in the compose window etc.).
I have manged to attach to the click even of the button and show a dialog when the button is clicked, by using:
addEventListener("click", function(e) { ......... }, true);
But I cannot stop the email from being sent. I have tried using:
e.stopPropagation();
e.preventDefault();
return false;
How can I stop Gmail from sending the email?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您提到的那些可以阻止浏览器中内置的默认操作,并停止将事件传播到 DOM 层次结构中的父元素。您可能需要获取 Gmail 的事件监听器并用它做一些事情 - 用您的函数包装它(因此,删除原始事件监听器并绑定您的函数,该函数显示一个对话框,然后调用 Gmail 的对话框)。目前,当您仅添加事件侦听器时,有两个独立的事件处理程序。
这些帖子可能有用:
如何查找 DOM 节点上的事件侦听器?
如何检查是否是否有附加到元素/文档的 JavaScript 事件侦听器/处理程序?
I think that those mentioned by you can prevent default action that is built-in in browser, and stop propagation of event to parent elements in DOM hierarchy. You probably need to get the Gmail's event listener and do something with it - wrap it with your function (so, remove original event listener and bind your function, which displays a dialog and then invoke Gmail's one). Currently, when you only add an event listener, there are two independent event handlers.
Those posts might be useful:
How to find event listeners on a DOM node?
How to check if any JavaScript event listeners/handlers attached to an element/document?