Hide your Email Address from Spammers with a Simple JavaScript

Javascripts to hide email addresses from spammers have been around for a while but perhaps you missed this one. I have been using it more and more for my client’s HTML-based websites.

If the email address is: joe@mydomain.com, most websites use:


That line of basic HTML is easily harvested by spambots. Within a few weeks, the spam will start trickling in. After a few months, there will be a flood of annoying spam emails.

What can you do? Start with a fresh email address and use this small JavaScript:

<code><script type="text/javascript"><!--
var name = "joe";
var domain = "mydomain.com";
document.write('<a href=\"mailto:' + name + '@' + domain + '\">');
document.write(name + '@' + domain + '</a>');
// --></script></code>

Simply replace the email address segments in lines 2 and 3. Then, paste the JavaScript into the HTML code for the page (replacing the mailto code). You are done!