Created
          October 4, 2015 19:26 
        
      - 
      
 - 
        
Save cameronrye/0d55741c12815e7544af to your computer and use it in GitHub Desktop.  
    mailto: URLs in JavaScript
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // http://xion.io/post/code/js-mailto-urls.html | |
| function getMailtoUrl(to, subject, body) { | |
| var args = []; | |
| if (typeof subject !== 'undefined') { | |
| args.push('subject=' + encodeURIComponent(subject)); | |
| } | |
| if (typeof body !== 'undefined') { | |
| args.push('body=' + encodeURIComponent(body)) | |
| } | |
| var url = 'mailto:' + encodeURIComponent(to); | |
| if (args.length > 0) { | |
| url += '?' + args.join('&'); | |
| } | |
| return url; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment