如何防止mailto事件在浏览器中打开新标签页

问题描述:

我正在使用填充了JavaScript的mailto:在整个Web应用程序中发送信息,但是每次用户按下发送按钮时,它都会在浏览器中打开一个新标签,然后再打开邮件应用程序(Outlook,Gmail等).

I am using a mailto: filled in JavaScript to send information throughout my web application, but everytime a user presses the Send button, it opens a new tab in the browser before opening the mailing application (Outlook, Gmail, etc).

有什么方法可以防止空白标签打开?

Is there any way to prevent the blank tab from opening?

以下所有主要浏览器都遇到此问题:Internet Explorer,Firefox和Google Chrome.

This issue is encountered in all following major browsers : Internet Explorer, Firefox and Google Chrome.

我正在使用window.open()发送电子邮件,是否有已知的替代方法?

I am using window.open() to send emails, is there any known alternatives?

这是我发送电子邮件的方式:

Here is how I send the email:

var mailto_link = 'mailto:'+email+'?subject='+subject+'&body='+body_message;
var win = window.open(mailto_link,'emailWindow');

我不想使用window.location.href,因为我在用户发送电子邮件后显示了一条消息.

I don't want to use window.location.href since I am displaying a message after the user sent the email.

谢谢您的编辑.确实有另一种选择:

Thank you for the edit. There is indeed an alternative:

window.location.href = "mailto:mail@domain.tld";
alert("Thank you!");

我不想使用window.location.href,因为我正在显示 用户发送电子邮件后显示的消息.

I don't want to use window.location.href since I am displaying a message after the user sent the email.

我真的没有得到这个.将mailto:window.location.href

I did not really get this one. You are not leaving the website when using mailto: with window.location.href