Protecting email addresses on web pages

Sat, 23 Feb 2008 | Comments

I was adding my email address to http://peerassembly.com and used a little javascript snippit to hide the email address from simple (read: stupid) email harvester bots. It’s so short, it hardly warrants a post but maybe someone will find it the next time they’re putting a contact email address on a web page and save themselves a ton of spam!

If you don’t have it already, add prototype.js to your page:

  <script src="javascripts/prototype.js" type="text/javascript" charset="utf-8"></script>

At the place in your page where you put your email address, replace it with:

<span id="email">info</span>

Then, add this to your page:

  <script type="text/javascript">
  var a = "info" + "&#64;" + "peerassembly.com";
  $('email').update('<a href="mailto:'+a+'">'+a+'</a>');
  </script>

That’s it – when the javascript executes, it will insert the email link in your page.