Skip to content

Instantly share code, notes, and snippets.

@cowboymathu
Last active August 29, 2015 14:20
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 cowboymathu/d79e742718994bf2daa6 to your computer and use it in GitHub Desktop.
Save cowboymathu/d79e742718994bf2daa6 to your computer and use it in GitHub Desktop.
function escapeAll(str) {
var hexString = "";
for (var index=0; index<str.length; index++) {
var charCode = str.charCodeAt(index);
var h = charCode.toString(16).toUpperCase();
if (h.length == 1) {
h = "0" + h;
}
h = "%" + h;
hexString += h;
}
return hexString;
}
jQuery(function() {
jQuery('a[href^="mailto:"]').each(function() {
var url = this.href.split("mailto:");
var email = url[1].split('@');
urlToEscape = email[0] + '@';
this.href = "mailto:" + escapeAll(urlToEscape) + email[1];
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment