How to Prevent Spam Bots from Harvesting Your Email Address

How do we keep this site running? This post may contain affiliate links — the cost is the same to you, but we get a referral fee. Compensation does not affect rankings. Thanks!

Junk emailThe basic idea here is to encode your email address so it will not be easily harvested by robots crawling the Internet in search of email addresses. These robots are based on a script that searches for the “” string (this example will probably be harvested, but it won’t do them any good since the email address is not valid). By using JavaScript to generate the email string, we can break up this pattern so it will no longer be recognizable by the email harvesters (this example is based on an email alias from our old company name). We also escape certain alphabetic characters. Visit our html escape characters article for a complete list of valid html (and xhtml) escape characters.

<script type="text/javascript">
emailMe=('&#105;nf' + 'o' + '@' + '&#67;ontra&#99;' + 'tWebDe' + 'velopme' + 'nt.&#99;om')
document.write('<a href="mailto:' + emailMe + '">' + emailMe + '</a>')

<noscript>Our email address is scripted to prevent spam. If you cannot see it, please enable JavaScript or use the Contact Form below to contact me.</noscript>

Since not everyone has JavaScript support turned on, it is a good idea to include the <noscript> tags to notify these users that they are missing out on a feature that relies on JavaScript. In our case, we notify the user that we have used the JavaScript to reduce email spam, and leave them with two options. One, they can turn on JavaScript so they may see our email address, or two, they can use our contact form to get in touch with us.

Alex bring a series of in-depth articles on search marketing and content management systems as well as troubleshooting tips to We Rock Your Web's collection. He is an avid tennis player, nature enthusiast, and hiker, and enjoys spending time with his wife, friends, and dogs, Bella and Lily.

Leave a Reply

2 Comments on "How to Prevent Spam Bots from Harvesting Your Email Address"


Nowadays lots of spammers got into our e mail address and they are that annoying and even pissed us off most of the time. I haven’t try to open yet my JavaScript. But I will include it later. Thank you for the information. I hope it works.



Thank you! I’ve been getting soooo much spam this year. I hope this javascript anti-spam technique will help!


Send this to a friend