最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript location.href to mailto triggers a GET HTTP that gets canceled in Chrome - Stack Overflow

programmeradmin1浏览0评论

I have a button that triggers the following javascript function:

function sendEmail() {
    var mail = 'mailto:[email protected]';
    location.href = mail;
};

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

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

How can I get the email client to open?

I have a button that triggers the following javascript function:

function sendEmail() {
    var mail = 'mailto:[email protected]';
    location.href = mail;
};

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

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

How can I get the email client to open?

Share Improve this question asked Feb 18, 2013 at 13:17 Timothée HENRYTimothée HENRY 14.6k22 gold badges98 silver badges138 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 5

It works for me. But you can try this

function sendEmail() {
    var mail = 'mailto:[email protected]';
    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
};
发布评论

评论列表(0)

  1. 暂无评论