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=('inf' + 'o' + '@' + 'Contrac' + 'tWebDe' + 'velopme' + 'nt.com')
document.write('<a href="mailto:' + emailMe + '">' + emailMe + '</a>')
//-->
</script>
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.
All Content © 2005 - 2008 Contract Web Development, Inc. All Rights Reserved. Privacy Policy | Terms of Use | Powered by Drupal
Encoding email addresses
Thank you! I've been getting soooo much spam this year. I hope this javascript anti-spam technique will help!