如何在IE11中设置Mailto链接?

时间:2019-08-14 12:04:04

标签: html internet-explorer

我正在使用mailto链接设置HTML表单。它可以在Google Chrome浏览器中正常运行,并且可以在Outlook中预先填充表单主体。但是,当我在Internet Explorer 11中执行相同的操作时,不会填充电子邮件正文。Example form is here

这是IE11设置的问题吗?还是我想念什么?

1 个答案:

答案 0 :(得分:1)

我已经重现了该问题,似乎当我们单击“发送”按钮以在IE浏览器中发送电子邮件时,该URL仅包含mailto属性(不包含电子邮件正文),并且不会附加电子邮件正文到网址。因此,电子邮件正文为空。

为解决此问题,我建议您可以收集电子邮件信息,然后对电子邮件进行编码(请参阅W3's URL Encoding),最后发送电子邮件。代码如下:

<script>
    window.onload = function () {
        var eTo = encodeURI("sales@example.com"); // get the receiver 
        var eSubj = encodeURI("Submission From Quote Creator"); //get the email submit.
        var emailbody = "Please enter your contact information and message here: \n\n\nQuote:\n#17350  IFW 2-inch -$829.00\n"; //get the email body.
        var eBody = encodeURI(emailbody.replace("#","23%"));

        var email = "mailto:" + eTo + "?subject=" + eSubj + "&body=" + eBody;
        console.log(email);
        document.getElementById("sales").href = email;
    }
</script>
<a href="" id="sales">send email</a>