Skip to content

Instantly share code, notes, and snippets.

@iamstuartwilson
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamstuartwilson/986592afcb5d5cc38536 to your computer and use it in GitHub Desktop.
Save iamstuartwilson/986592afcb5d5cc38536 to your computer and use it in GitHub Desktop.
jQuery mailto param scraper
$('a[href^="mailto:"]').click(function(e) {
var uri = $(this).attr('href');
var emailRegEx = new RegExp(/\mailto:(.*?)\?/);
var params = uri.replace(emailRegEx, '').split('&');
var email = uri.match(emailRegEx);
var fields = {
email: email ? email[1] : null,
subject: null,
body: null
};
for (var i = 0; i < params.length; i ++) {
var vals = params[i].split('=');
fields[vals[0]] = vals[1];
}
// Ouput fields from URI
console.log(fields);
e.preventDefault();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment