在 mailto link 中使用时,换行符未正确显示
Line break doesn't show correctly when used in a mailto link
ts
send(): void {
const body: string = `First Name: ${this.form.value.firstName}` + '\n' + `Last Name:${this.form.value.lastName}`;
console.log('body', body);
const url: string = `mailto:me@y.com?Subject=Sell My House&body=${body}`;
window.open(url);
}
Console.log 正确显示:
body First Name: sampath
Last Name:lokuge
但是为什么邮件客户端显示不正确
OP的反馈
我是这样做的:即%0D%0A
const body: string = `First Name: ${this.form.value.firstName}` + '%0D%0A' + `Last Name: ${this.form.value.lastName}`
原创
这是 HTML 和白色 space 的正常行为。所有的白色space被压缩成一个,并且被认为是一个单一的space。
https://developer.mozilla.org/en-US/docs/Glossary/Whitespace
css white-space 属性 可以修复 white-space: pre-line
可能是你想要的,但还有其他选择
https://developer.mozilla.org/en-US/docs/Web/CSS/white-space
现在,无论天气与否,您的电子邮件客户端都会尊重 css white-space
属性 您需要进行测试。否则,您可能需要添加 HTML 换行符 <br>
或将每行换行在 <div>
或 <p>
中
ts
send(): void {
const body: string = `First Name: ${this.form.value.firstName}` + '\n' + `Last Name:${this.form.value.lastName}`;
console.log('body', body);
const url: string = `mailto:me@y.com?Subject=Sell My House&body=${body}`;
window.open(url);
}
Console.log 正确显示:
body First Name: sampath
Last Name:lokuge
但是为什么邮件客户端显示不正确
OP的反馈
我是这样做的:即%0D%0A
const body: string = `First Name: ${this.form.value.firstName}` + '%0D%0A' + `Last Name: ${this.form.value.lastName}`
原创
这是 HTML 和白色 space 的正常行为。所有的白色space被压缩成一个,并且被认为是一个单一的space。
https://developer.mozilla.org/en-US/docs/Glossary/Whitespace
css white-space 属性 可以修复 white-space: pre-line
可能是你想要的,但还有其他选择
https://developer.mozilla.org/en-US/docs/Web/CSS/white-space
现在,无论天气与否,您的电子邮件客户端都会尊重 css white-space
属性 您需要进行测试。否则,您可能需要添加 HTML 换行符 <br>
或将每行换行在 <div>
或 <p>