By Dan_Thies
Almost every website operator wants search engine
spiders to visit. After all, search engines are the best
source of free traffic on the web. In the event that you
don't want them to visit, they are easily kept at bay
with a properly formatted "robots.txt" file.
Unfortunately, there's another group of spiders out
there crawling the web, with an entirely different
purpose. These are the spiders that visit site after
site, collecting email addresses. You may know them as
spam bots, email harvesters, or any number of
unpublishable names.
When it comes to controlling these rogue spiders,
robots.txt simply won't get the job done. In fact, most
spam robots will ignore robots.txt. That doesn't mean
you have to give up, and just let them have their way.
In this short tutorial, I'll teach you how to hide your
email addresses from them.
One of the weaknesses that
spiders of all kinds suffer from is an inability to
process scripts. Adding a small snippet of _Javascript
in place of an email address effectively renders the
address invisible to spiders, while leaving it
accessible to your visitors with all but the most
primitive web browsers.
In the three examples below, simply substitute your
username (the first half of your email address,
everything before the @ symbol) and your hostname
(everything after the @ symbol). To use the scripts,
just insert them into your page's HTML wherever you need
them to be displayed.
Example 1: Creating A Spam-Proof Mailto Link This
snippet of code creates a clickable link that launches
the visitor's email application, assuming that their
system is configured to work with mailto links. You can
replace the link text with your own message, but see
example 2 if you want to display your email address as
the link text.
<script language=_javascript> <!-- var username =
"username"; var hostname = "yourdomain.com"; var
linktext = "Click Here To Send Me Email"; document.write("<a
href=" + "mail" + "tox" + username + "@" + hostname +
">" + linktext + "</a>") //--> </script>
Example 2: A Spam-Proof Mailto Link With Your
Email Address Showing
Some visitors won't be able to use a mailto link, and
will instead need to read the email address. No problem,
just use the snippet below instead.
<script language=_javascript>
<!--
var username = "username";
var hostname = "yourdomain.com";
var linktext = username + "@" + hostname;
document.write("<a href=" + "mail" + "tox" + username +
"@" + hostname + ">" + linktext + "</a>")
//-->
</script>
Example 3: Display Your Email Address Without A
Mailto Link
Sometimes, you just want to give your email address
without making it a clickable link - here's a snippet
that accomplishes just that:
<script language=_javascript>
<!--
var username = "username";
var hostname = "yourdomain.com";
var linktext = username + "@" + hostname;
document.write(username + "@" + hostname)
//-->
</script>