5

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

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

在 Chrome 中,此函数会触发对“mailto:contact@test.com”的 HTTP GET,但 HTTP GET 在 Inspect Element Network 选项卡中具有“已取消”状态,并且电子邮件客户端未打开。

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

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

4

1 回答 1

5

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

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
};
于 2013-02-18T13:26:11.240 回答