title: Encoding json data for a mailto link
body: <p>How do I properly encode a mailto link with JSON data in the query parameters so that the link works as expected when some of the JSON data possibly includes spaces?</p>
  
  <p>Here is a simple example:</p>
  
  <pre><code>var data = {
   "Test": "Property with spaces"
  };
  
  var mailTo = 'mailto:?body=http://www.google.com/?body=' + JSON.stringify(data);
  
  document.getElementById("link").href = mailTo;
  </code></pre>
  
  <p>The resulting link in the email after clicking the link looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/p9Gx8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/p9Gx8.png" alt="link"></a></p>
  
  <p>Here is a JSBin showing what I am talking about:</p>
  
  <p><a href="https://jsbin.com/vuweyemeji/1/edit?html,js,output" rel="nofollow noreferrer">https://jsbin.com/vuweyemeji/1/edit?html,js,output</a></p>
  
  <p>Edit: Adding encodeURI() or encodeURIComponent() doesn't seem to work for me.  I tried adding either of those methods around the data object and when I click the mailto link the url still looks the same in outlook.</p>