title: Passing special characters to mailto body blows up JavaScript
body: <p>I have a C# ASP.NET app that creates a JavaScript array of values for some user profile information. Client-side, I use jQuery/JavaScript to read the array and generate a mailto link. Some of the fields can contain special characters, such as <code>' &amp; = / \ "</code>. </p>
  
  <p>Here's the C# code:</p>
  
  <pre><code>private String generateElementsArray(){
    StringBuilder sb = new StringBuilder();
    sb.Append("var currentElements = { currentUserName: '");
    sb.Append(currentUserName);
    sb.Append("', currentUserEmail: '");
    sb.Append(currentUserEmail);
    sb.Append("', currentSite: '");
    sb.Append(currentSite);
    sb.Append("', currentTitle: '");
    sb.Append(currentTitle);
    sb.Append("'}");
    return sb.ToString();
  }    
  </code></pre>
  
  <p>I write the value of the above method to the page, which produces this JavaScript:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;var currentElements = { currentUserName: 'Alex', currentUserEmail: 'myemailID', currentSite: 'Helpdesk', currentTitle: 'Phone User Guides &amp; Troubleshooting'}&lt;/script&gt;
  </code></pre>
  
  <p>Then I generate the email link using this JavaScript code, attaching the anchor tag to an element on the page:</p>
  
  <pre><code>function generateEmailTo(){
    var body = currentElements.currentUserName + ' has shared a page with you on the intranet.%0A%0APage Title: %22' +
      currentElements.currentTitle.replace("&amp;","and")  + '%22%0A' + $(location).attr('href').replace('#',''); 
    var subject = currentElements.currentUserName + ' has shared a page with you on the intranet';
    var mailto = 'mailto: ?body=' + body + '&amp;subject=' + subject;
    var anchor = '&lt;a href="' + mailto + '"&gt;&lt;/a&gt;';
  
    $("#email-placeholder").wrap(anchor);
  }
  ....
  
  &lt;img id="email-placeholder" title="Send this page to a friend." src="&lt;%= baseUrl %&gt;/SiteAssets/media/icons/email-icon.gif"/&gt;
  </code></pre>
  
  <p>For the mailto body text, I've noticed that it only takes a small set of the encoded characters, such as <code>%22</code> for double-quotes, and <code>%0A</code> for line breaks. How do I pass the special characters such as single quotes, ampersands, etc., to the mailto body text and keep JavaScript happy?</p>