Last active
December 21, 2015 13:58
-
-
Save timhudson/6315903 to your computer and use it in GitHub Desktop.
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
/* Simple spam protection for email addresses using jQuery. | |
* Well, the protection isn’t jQuery-based, but you get the idea. | |
* This snippet allows you to slightly ‘obfuscate’ email addresses to make it harder for spambots to harvest them, while still offering a readable address to your visitors. | |
* E.g. Changed "at" to "atty" and "dot" to "dotty" to confuse some of the more intelligent harvesters. | |
* <a href="mailto:foo(atty)example(dotty)co(dotty)uk">foo aty example dotty co dotty uk</a> | |
* → | |
* <a href="mailto:[email protected]">[email protected]</a> | |
*/ | |
$(function() { | |
$('a[href^="mailto:"]').each(function() { | |
this.href = this.href.replace('(atty)', '@').replace(/\(dotty\)/g, '.'); | |
// Remove this line if you don't want to set the email address as link text: | |
this.innerHTML = this.href.replace('mailto:', ''); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment