One of the more irritating downsides of maintaining a popular website, is having to wade through twenty spam emails to get to a single genuine one! Somehow it makes common sense to place as few barriers between yourself and potential customers as possible – the more complex you make a contact form, the less likely people will actually be to complete it correctly.  As an experienced writer of web crawlers and various digital critters, The Manchester SEO Blog author will tonight be dishing out some neat little Javascript tricks that will outfox nine out of ten spambots.

Thinking Like One of Them

First off, you have to think like a machine! Picture this: a bot has just fetched your web page, and is now carefully carving the <HTML> tags away from your juicey plain text content. Within this text it will search for some indication of an email address.

Using Javascript To Protect Your Email

Because Javascript is a client-side application, most crawlers will completely ignore it.  It is computationally costly, and aside from Google’s neat indexing of ticker tape text, we cannot expect a great deal of text content to come from Javascript.  This enables you to ‘hide’ your email in a document.write statement, using the character code for @ to avoid it even looking like an email to those that do process Javascript!
<script type="text/javascript">
hideme=('roger' + String.fromCharCode(64) + 'just.roger-it.co.uk')
document.write(
'<A href="mailto:' + hideme + '">'
+ hideme + '</a>'
)
</script>

If you wish, you could take this one step further and replace the mailto: part of the link with the ASCII character codes which will make it even harder to detect.
<script type="text/javascript">
hideme=('roger' + String.fromCharCode(64) + 'just.roger-it.co.uk')
document.write(
'<A href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;' + hideme + '">'
+ hideme + '</a>'
)
</script>

Here is the code running from this page:

How To Cope When Human Visitor Does Not Have Javascript Enabled

The one obvious weakness in this tactic is the dependence upon your visitors having Javascript enabled. While in practice this will mean the code works for the vast majority, it always helps to be prepared for those which might not be so lucky.  What I find most helpful without compremising all this trickery is to simply use the <noscript> tag below the Javascript:
<noscript>
<form method="post" action="contact.php">
<input type="text" name="username" >
<input type="text" name="email" >
<textarea name="comment" cols=40 rows=6 ></textarea >
<img src="captcha.php" alt="Please Enter Captcha Text" >
<input type="text" name="captcha" >
</form>
</noscript>

So there you have it. The ayes have it … the spambots (hopefully!) don’t. Using this method you should be able to minimize the number of mailing lists your email is added to, and not risk any of your points of contact with potential customers!

  • Share/Bookmark

Tags: , , , , , ,

One Response to “Javascript To Protect Your eMail from Spambots, Keep it Visible to Humans”

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>