Last active
August 29, 2015 14:14
-
-
Save iamstuartwilson/986592afcb5d5cc38536 to your computer and use it in GitHub Desktop.
jQuery mailto param scraper
This file contains 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
$('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