Skip to content

Instantly share code, notes, and snippets.

@cameronrye
Created October 4, 2015 19:26
Show Gist options
  • Save cameronrye/0d55741c12815e7544af to your computer and use it in GitHub Desktop.
Save cameronrye/0d55741c12815e7544af to your computer and use it in GitHub Desktop.
mailto: URLs in JavaScript
// 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