[英]How to fix not showing line break in body while using mailto?
My code:我的代码:
<a href="mailto:anything@any.com?subject=This%20is%20Subject&body=Hello%0D%0A%0D%0Aworld..">
click here to mail me
</a>
Expected output:预期 output:
What i am getting as output now:我现在得到的是 output:
I tried using %0D%0A
but it doesn't work.我尝试使用
%0D%0A
但它不起作用。 Also i tried few java script methods from here But those don't seems to work.我也从这里尝试了一些 java 脚本方法,但这些方法似乎不起作用。
The app i used to check mailto: output is default Gmail App from my android device.我用来检查邮件的应用程序:output 是我的 android 设备中的默认 Gmail 应用程序。
EDIT [SOLUTION]编辑[解决方案]
Just using <br>
tag works fine with third party applications like gmail for android.只需使用
<br>
标签即可与第三方应用程序(例如 gmail for android)一起正常工作。
%0D%0A are the carry return and line feed characters, use %20 for space as you do in the subject: %0D%0A 是进位返回和换行字符,使用 %20 作为空格,就像您在主题中所做的那样:
<a href="mailto:anything@any.com?subject=This%20is%20Subject&body=Hello%20world..">
click here to mail me
</a>
And if you want a line break use %0D%0A
as in:如果您想要换行符,请使用
%0D%0A
,如下所示:
<a href="mailto:anything@any.com?subject=This%20is%20Subject&body=Hello%0D%0Aworld..">
click here to mail me
</a>
You can check what this values mean in a ascii table if you check the hexadecimal value you see what A, D, E and 20 are equal to.如果您检查十六进制值,您可以查看这些值在ascii 表中的含义,您会看到 A、D、E 和 20 等于什么。
Just using <br>
tag, works fine with third party applications like gmail for android.只需使用
<br>
标签,就可以很好地与第三方应用程序(例如 gmail for android)配合使用。
Fixed code,固定代码,
<a href="mailto:anything@any.com?subject=This%20is%20Subject&body=Hello<br><br>world..">
click here to mail me
</a>
Update 09 Sep 2020 This has been changed again in a recent Gmail release - eg version 2020.08.09.327326543.Release
- \r\n
for line breaks when using mailto:
now works again and <br>
does not. 2020 年 9 月 9 日更新这已在最近的 Gmail 版本中再次更改 - 例如版本
2020.08.09.327326543.Release
- \r\n
用于使用mailto:
现在再次起作用,而<br>
不起作用。
I can only assume it was a regression bug rather than an intentional change in the Gmail app which has now been fixed.我只能假设这是一个回归错误,而不是 Gmail 应用程序的故意更改,该应用程序现已修复。
Original answer:原答案:
I've seen an issue arise recently in my Android apps which have been using encoded \r\n
for line breaks when using mailto:
to open Gmail as the default email client.我最近在我的 Android 应用程序中看到了一个问题,这些应用程序在使用
mailto:
时一直使用编码的\r\n
换行符:打开 Gmail 作为默认的 email 客户端。 While this previously worked fine, now the line break is appearing as a space.虽然这以前工作正常,但现在换行符显示为一个空格。
Upon doing some testing, it appears that the behaviour of the Gmail app has changed in a recent update.在进行一些测试后,Gmail 应用程序的行为似乎在最近的更新中发生了变化。
I created a test page which contains two links, one using encoded \r\n
and one using <br>
for a line break in the body:我创建了一个包含两个链接的测试页面,一个使用编码的
\r\n
,一个使用<br>
用于正文中的换行符:
mailto:anything@any.com?body=Hello%0D%0Aworld
mailto:anything@any.com?body=Hello<br>world
In an Android Emulator running Android 10/API 29 with Gmail app version of 2019.05.12.250526289.release
:在 Android 仿真器中运行 Android 10/API 29 和 Gmail 应用程序版本
2019.05.12.250526289.release
:
The \r\n
link works correctly: \r\n
链接正常工作:
But the <br>
link does not:但是
<br>
链接没有:
In an Android Emulator running Android 11 Beta/API 30 with Gmail app version of 2020.04.29.309137422.release
:在运行 Android 11 Beta/API 30 和 Gmail 应用程序版本
2020.04.29.309137422.release
的 Android 仿真器中:
The <br>
link works correctly: <br>
链接正常工作:
But the \r\n
link does not:但是
\r\n
链接没有:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.