【发布时间】:2012-05-08 12:54:46
【问题描述】:
无法让多行在 mailto 链接中正常工作
就我而言,我正在使用 Outlook 默认邮件阅读器对其进行测试。
以下内容放在一个锚href中:
mailto:email@address.com?&subject=test&body=type%20your&body=message%20here
电子邮件正文中仅显示“此处的消息”。 (不管我用的是chrome还是IE)
想法?
【问题讨论】:
无法让多行在 mailto 链接中正常工作
就我而言,我正在使用 Outlook 默认邮件阅读器对其进行测试。
以下内容放在一个锚href中:
mailto:email@address.com?&subject=test&body=type%20your&body=message%20here
电子邮件正文中仅显示“此处的消息”。 (不管我用的是chrome还是IE)
想法?
【问题讨论】:
您可以使用URL encoding 将换行符编码为%0A。
mailto:email@address.com?subject=test&body=type%20your%0Amessage%20here
虽然上述方法在很多情况下都有效,但用户 olibre points out 表示,管理 mailto URI 方案的 RFC 指定应使用 %0D%0A(回车 + 换行)而不是 %0A(换行) .另见:Newline Representations。
【讨论】:
$0A 就是 escape( "\n" )
encodeURIComponent 对 URI 组件进行编码。
mailto 字符串中使用单个body 参数
%0D%0A 作为换行符mailto URI Scheme 由 RFC2368(1998 年 7 月)和 RFC6068(2010 年 10 月)指定。
以下是最后一个 RFC 的 section 5 的摘录:
[...] 消息正文中的换行符必须使用
"%0D%0A"编码。
实现可以在消息正文中添加最后的换行符 即使正文中没有尾随"%0D%0A"[...]
另请参阅section 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.";
【讨论】:
encodeURIComponent,而是。 See here.
这就是我做的,只需添加\n并使用encodeURIComponent
例子
var emailBody = "1st line.\n 2nd line \n 3rd line";
emailBody = encodeURIComponent(emailBody);
href = "mailto:me@somesite.com?body=" + emailBody;
【讨论】:
include 用于 encodeURIComponent 是什么?