Wednesday, October 18, 2006

How to Hide Email Addresses from Spammers

Are you tired of spam? I know I am.

Hard-core spammers use what are termed 'bot' to crawl the web and harvest email address. These bots search through page source code looking for email addresses. Because of the fixed format of an email address, they are pretty easy for to automatically extract from page code.

Here's a handy way to hide email address from most bots using JavaScript. Being client side executed, JavaScripts aren't run until the page is assembled by the client. Although most automated bots can see the JavaScript at the code level, they aren't able to execute it.

What this littel code does is seperate your email into variables, which JavaScript then assembles. Bot aren't able to assemble the parts, thus don't see the email address.
<script language=javascript>
var linktext = "Email the Webmaster";
var part1 = "webmaster";
var part2 = "";

document.write("<a href=" + "mail" + "to:" + part1 + "@" + par2 + ">" +
linktext + "</a>")

Replace 'Email the Webmaster' with whatever link text you want, 'webmaster' with the front part of your email address, and '' woth the rest of your email address. Notice that I also break up the 'mailto' portion as well.

Simply place this little script wherever you want. Users (with JavaScript enabled) will be able to see it, but the bots won't!

No comments: