Html mailto 链接多个正文行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10356329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 00:01:46  来源:igfitidea点击:

mailto link multiple body lines

htmloutlookmailto

提问by KevinDeus

having trouble getting multiple lines to work correctly in a mailto link

无法在 mailto 链接中使多行正常工作

In my case I'm testing it with an Outlook default mail reader.

就我而言,我正在使用 Outlook 默认邮件阅读器对其进行测试。

The following is put in an anchor href:

以下内容放在锚点 href 中:

mailto:[email protected]?&subject=test&body=type%20your&body=message%20here

mailto:[email protected]?&subject=test&body=type%20your&body=message%20here

only "message here" shows up in the email body. (whether I use chrome or IE)

电子邮件正文中仅显示“此处的消息”。(无论我使用 chrome 还是 IE)

thoughts?

想法?

回答by cyang

You can use URL encodingto encode the newline as %0A.

您可以使用URL 编码将换行符编码为%0A.

mailto:[email protected]?subject=test&body=type%20your%0Amessage%20here

mailto:[email protected]?subject=test&body=type%20your%0Amessage%20here

While the above appears to work in many cases, user olibre points outthat the RFC governing the mailto URI scheme specifies that %0D%0A(carriage return + line feed) should be used instead of %0A(line feed). See also: Newline Representations.

虽然上述似乎在许多情况下都有效,但用户 olibre指出管理 mailto URI 方案的 RFC 指定%0D%0A应该使用(回车+换行)而不是%0A(换行)。另请参阅:换行表示

回答by olibre

  1. Use a single bodyparameterwithin the mailtostring
  2. Use %0D%0Aas newline
  1. bodymailto字符串中使用单个参数
  2. 使用%0D%0A如换行符

The mailtoURI Schemeis specified by by RFC2368(July 1998) and RFC6068(October 2010).
Below is an extract of section 5of this last RFC:

mailtoURI方案是通过指定由RFC2368(1998年7月)和RFC6068(2010年10月)。
以下是最后一个 RFC第 5 节的摘录:

[...] line breaks in the body of a message MUST be encoded with "%0D%0A".
Implementations MAY add a final line break to the body of a message even if there is no trailing "%0D%0A"in the body [...]

[...] 消息正文中的换行符必须使用"%0D%0A".
即使正文中没有尾随"%0D%0A"[...]

See also in section 6the example from the same RFC:

另请参阅第 6 节中来自同一 RFC 的示例:

<mailto:[email protected]?body=send%20current-issue%0D%0Asend%20index>

The above mailtobody corresponds to:

上述mailto主体对应于:

send current-issue
send index

回答by lokeshjain2008

To get body lines use escape()

要获得身体线条,请使用 escape()

body_line =  escape("\n");

so

所以

href = "mailto:[email protected]?body=hello,"+body_line+"I like this.";

回答by kiranvj

This is what I do, just add \nand use encodeURIComponent

这就是我所做的,只需添加\n和使用encodeURIComponent

Example

例子

var emailBody = "1st line.\n 2nd line \n 3rd line";

emailBody = encodeURIComponent(emailBody);

href = "mailto:[email protected]?body=" + emailBody;

Check encodeURIComponentdocs

检查encodeURIComponent文档