Anti-Spam Email Obfuscating jQuery Anchor Link

  1. Replace the "@" and "." in your email address with "~" and "*", respectively:
    me@example.com => me~example*com
  2. Reverse the whole email string:
    me~example*com => moc*elpmaxe~em
  3. Add the following code where you would like the email address to appear, replacing the example reversed address:
    <script id="liame" type="text/javascript">
    var s = 'moc*elpmaxe~em';
    var e = s.replace( '~', '@' ).replace( '*', '.' ).split( '' ).reverse().join( '' );
    $( '#liame' ).after( '<a>' ).next().attr( 'href', 'mail' + 'to:' + e ).text( e );
    </script>
  4. Optional: For ultra security, add some randomness (useless code) in case spammers catch wind of this specific code. Change the special characters, change the script ID from "liame", add some gibberish variables, etc.
  5. Optional: If you absolutely need to cater to JavaScript being disabled, add a <noscript> tag with your own human-guessable obfuscation, such as "me (at) example (dot) com". Note that this will decrease the effectiveness.

If you are not using jQuery, here is a resource: youmightnotneedjquery.com. The logic can be quite quickly ported. If you are using a server-side language, you could go all out and really randomize your implementation.

Comments

comments powered by Disqus

danielupshaw.com