I created an html page that has a mailto link. The body of the email has escaped characters (\', \", \n, \r) none of which seem to be recognized by Yahoo Mail (when yahoo mail is set to my default email). The mailto link parses the copy in the body without doing carriage returns(\r) or new lines (\n) and when it gets to a single (\') or double quote (\") it stops parsing the copy. I haven't run into any fixes for this issue on the internet. If anyone has run into this issue and has a fix it would be greatly appreciated.
Asked
Active
Viewed 1,957 times
1 Answers
0
The mailto-link is a URI, so encode it accordingly. I think the correct function to use is encodeURIComponent
for each value
.
So:
var link = "mailto:john@doe.com?subject="
+ encodeURIComponent(subject) + "&body="
+ encodeURIComponent(body)

Halcyon
- 57,230
- 10
- 89
- 128
-
Thanks for your response Frits. The encodeURIComponent() won't process all the copy but When I use encodeURI() it encodes everything except the single quote but will not process the carriage returns (\r) or new lines (\n). – user2216811 Mar 27 '13 at 21:24
-
`var uri="hello\'\"\n\r"; document.write(encodeURI(uri));` yeilds `hello'%22%0A%0D` – user2216811 Mar 27 '13 at 21:34
-
That looks fine to me. Keep in mind that HTML removes whitespace too. `document.write` does not give you an accurate representation of the string. Use `console.log`. – Halcyon Mar 28 '13 at 02:01