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

When you purchase through links on our site, we may earn a commission. Here’s how it works.

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.

Best Email Spam Filters & Blockers

Is your inbox getting flooded with junk mails that are obviously spam (and maybe some that are not so obvious)? There are hundreds of anti-spam solutions out there, some free, some paid, and some are themselves scams! Our experts help you reduce spam in your inbox with these hand-selected spam filters.

Tagged With: ,

The information provided through this website should not be used to diagnose or treat a health problem or disease; it is not intended to offer any legal opinion or advice or a substitute for professional safety advice or professional care. Please consult your health care provider, attorney, or product manual for professional advice. Products and services reviewed are provided by third parties; we are not responsible in any way for them, nor do we guarantee their functionality, utility, safety, or reliability. Our content is for educational purposes only.

Notify of
Oldest Most voted
Inline Feedbacks
View all comments