How To Prevent Spam Bots From Harvesting Your Email Address With JavaScript

To sustain this free service, we receive affiliate commissions via some of our links. This doesn’t affect rankings. Our review process.

Junk emailHow Does My Email Get Harvested?

The 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).

Hiding Your Email Address With JavaScript

There are several ways to hide your email address (such as using <code> around the @ symbol, replacing the @ symbol with its HTML character equivalent (&#64;), and more – but these are not as effective or secure as using js).

By using JavaScript to generate the email string, we can break up your email 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>

NoScript Tags For Non-JavaScript Users

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.

Spam filter buttonDid Your Email Address End Up On A Blacklist?

If you’re having trouble getting your emails to reach their destinations, or recipients are letting you know that your emails are frequently ending up in their spam folders, your email address may have ended up on an email blacklist. But have no fear! Our experts show you how to get it removed in our email spam blacklist guide.

About The Author:

Alex has been involved on the business side of the internet since the early 2000's. He holds both a Management Science degree from the University of California at San Diego as well as a Computer Science degree from NJIT.

We Rock Your Web had its roots back in 2004 as the tech blog for a web design and development company Alex founded that has grown and evolved into the parent company of We Rock Your Web.

While his foundation is rooted in web development, his expertise today lies in content and digital marketing, SEO, organic and paid search, analytics, and publishing. Alex is an avid tennis player, nature enthusiast, and hiker, and enjoys spending time with his wife, friends, and dogs.

Disclaimer: This website contains reviews, opinions and information regarding products and services manufactured or provided by third parties. We are not responsible in any way for such products and services, and nothing contained here should be construed as a guarantee of the functionality, utility, safety or reliability of any product or services reviewed or discussed. Please follow the directions provided by the manufacturer or service provider when using any product or service reviewed or discussed on this website.

Notify of
Oldest Most voted
Inline Feedbacks
View all comments

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!