Jun 02 2006

Anti-Spam JavaScript Email Link


Categories:

How to Prevent Spam Bots from Harvesting Your Email Address

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 "mailto:email@example.com" 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, as we have done on our Contact Information page, we can break up this pattern so it will no longer be recognizable by the email harvesters.  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>')
//-->
</script>

 

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.

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 my case, I notify the user that I have used the JavaScript to reduce email spam, and leave them with two options. One, they can turn on JavaScript so they may see my email address, or two, they can use my contact form to get in touch with me.

Average: 5 (1 vote)
Select your preferred way to display the comments and click "Save settings" to activate your changes.

Encoding email addresses

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

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Textual smileys will be replaced with graphical ones.

More information about formatting options

Captcha
This question is used to make sure you are a human visitor and to prevent spam submissions.
Copy the characters (respecting upper/lower case) from the image.