在mailto链接中,我遇到了多行文本无法正确工作的问题。
在我的测试中,我使用的是Outlook默认的邮件阅读器。
以下内容放置在锚点href中:
mailto:email@address.com?&subject=test&body=type%20your&body=message%20here
只有“message here”会显示在电子邮件正文中。(无论我使用Chrome还是IE)
您有什么想法?
body
参数放在mailto
字符串中。%0D%0A
作为换行符。mailto
URI协议由RFC2368(1998年7月)和RFC6068(2010年10月)进行了规定。
以下是最新RFC的第5节的摘录:
[...]消息正文中的换行符必须使用
"%0D%0A"
进行编码。
即使消息正文中没有尾随的"%0D%0A"
,实现程序也可以向消息正文中添加一个最终的换行符[...]
同样在第6节中有来自同一RFC的示例。
<mailto:infobot@example.com?body=send%20current-issue%0D%0Asend%20index>
上面的 mailto
主体对应于:
send current-issue
send index
使用 escape() 函数可以获取正文行
body_line = escape("\n");
所以
href = "mailto:me@my.com?body=hello,"+body_line+"I like this.";
这就是我的做法,只需添加\n
并使用encodeURIComponent
示例
var emailBody = "1st line.\n 2nd line \n 3rd line";
emailBody = encodeURIComponent(emailBody);
href = "mailto:me@somesite.com?body=" + emailBody;
请查看encodeURIComponent文档
encodeURIComponent
时需要用哪个 include
? - Frak
escape("\n")
。 - divillysausagesencodeURIComponent
来对URI组件进行编码。 - Cees Timmerman%0D%0A
时,它会打破超链接。 - Fiztban