1

I have an object literal

var object = {
    test: "test";
}

I call JSON.stringify on this object and append it to a query string

http://example.com?parameter={"test":"test"}

But when I append this query string into the mailto body, only this part

http://example.com?parameter=

got wrapped as an hyperlink while the rest is showed as plain text.

what I did was this:

window.location = "mailto:[email protected]?subject=subject&body=http://example.com?parameter={"test":"test"}";

And when the email client view showed, only the part before '=' got wrapped as hyperlink.

Frank Tian
  • 787
  • 3
  • 8
  • 22

2 Answers2

3

The application that renders the emails just doesn't consider { as part of a url, you can try encoding it. It wont look pretty though.
Something like

window.location = 'mailto:[email protected]?subject=subject&body=' + encodeURIComponent('http://example.com?parameter=' + encodeURIComponent('{"test":"test"}'));
Musa
  • 96,336
  • 17
  • 118
  • 137
2

This is actually related to accepted characters on URL. You should check this answer here: Characters allowed in a URL

So your link will work if you change this " to this ':

window.location = "mailto:[email protected]?subject=subject&body=http://example.com?parameter={'test':'test'}";

Check out this Fiddle to replace quotation marks

Community
  • 1
  • 1
jmartins
  • 991
  • 4
  • 16