我正在编写一个Chrome扩展,它修改Gmail窗口,以添加一个控件,允许用户在使用我们的专有协议发送消息还是作为常规电子邮件发送消息之间进行选择。我的问题是,一旦扩展确定了控件的状态,它如何拦截发送按钮发送的事件?
发布于 2019-10-30 10:25:58
使用Javascript最简单的方法是:
我在控制台中尝试了一个快速示例(在打开ComposeView时使用它):
// find the original button
const originalSendButton = document.querySelector('.mt-send');
// clone it
const fakeSendButton = originalSendButton.cloneNode(true);
fakeSendButton.addEventListener('click', () => alert('Fake Send Button clicked'));
// show fake button
originalSendButton.parentNode.replaceChild(fakeSendButton, originalSendButton);
// show original button if needed
// fakeSendButton.parentNode.replaceChild(originalSendButton, fakeSendButton);发布于 2022-07-11 20:17:28
最好的方法是使用ComposeView“预置”事件。添加事件侦听器(ComposeView.on("presending",回调)),并使用event.cancel()方法
ComposeView.on("presending", (e) => {e.cancel()});
你可以把你的逻辑放在回调中!
https://stackoverflow.com/questions/58611981
复制相似问题