对mailto的Javascript location.href触发在Chrome中取消的GET HTTP [英] Javascript location.href to mailto triggers a GET HTTP that gets canceled in Chrome

查看:73
本文介绍了对mailto的Javascript location.href触发在Chrome中取消的GET HTTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个触发以下javascript函数的按钮:

I have a button that triggers the following javascript function:

function sendEmail() {
    var mail = 'mailto:contact@test.com';
    location.href = mail;
};

在Chrome中,此功能触发HTTP GET到'mailto:contact@test.com',但HTTP GET在Inspect Element Network选项卡中具有'已取消'状态,并且未打开电子邮件客户端。

In Chrome, this function triggers an HTTP GET to 'mailto:contact@test.com', but the HTTP GET has a 'canceled' status in the Inspect Element Network tab, and the email client is not opened.

在IE中,电子邮件客户端也无法打开。

In IE, the email client also does not get opened.

如何让电子邮件客户端打开?

How can I get the email client to open?

推荐答案

它对我有用。但你可以尝试这个

It works for me. But you can try this

function sendEmail() {
    var mail = 'mailto:contact@test.com';
    var a = document.createElement('a');
    a.href = mail;
    document.body.appendChild(a); // Add to the DOM
    a.click();
    document.body.removeChild(a); // Remove it back
};

这篇关于对mailto的Javascript location.href触发在Chrome中取消的GET HTTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆