Protect your email address from spiders!

You may not realize it, but if your full email address is included in the source code of a web page, it's fair game for web crawling robot spiders (oh no! spiders!) to come along and add it to email spam lists. Thankfully theres a relatively simple way to protect your address with some JavaScript.

The function: prEmail()

  1. // hide email address from spiders
  2. function prEmail(user,domain,show) {
  3. addy = user + "@" + domain;
  4. display = (show)? show : addy;
  5. document.write("<a href=\"mailto:"+addy+"\" title=\""+addy+"\">"+display+"</a>");
  6. }
  7. source file: email-protection.txt

Now let's say your email address is bob@ack_spiders.com and you want the email link to say "e-mail Bob". To include your address safely, call prEmail() this way:

  • <p>Hey guys! If you have any questions, please <script type="text/javascript">prEmail('bob','ack_spiders.com','e-mail Bob');</script> right away!</p>

You can also leave out the third argument to display the actual address as the link text. Happy obfuscation!