SEARCH
  Web Programming JavaScript Time to Say Goodbye to Spam

Time to Say Goodbye to Spam

The_Beast JavaScript Oct 22, 2007

Time to Say Goodbye to SpamHaving trouble finding good, relevant emails in your inbox?! Have you lost a couple of contracts just because you did not reply on time to your partners? This article should guide you through finding the best way to fight against spam on your website.

A while ago, well, actually a couple of years ago all mail links posted on websites looked like myemail@myemail.com. Soon after that, bots started to gather those emails and people started to receive spam on their emails. The first protection for spam was developed. People were starting to post their mail like myemail at myemail dot com (sometimes 'at' and 'dot' were written in their mother tongue). But this way to protect personal emails soon became useless.

Different blacklists were developed, but sometimes these blacklists proved to be useless too, as they were not always up to date. So the tough part starts here. How do we actually protect ourselves from spam bots?

Some websites use CAPTCHAs. That image block with letters, numbers, somewhat distorted. But you all know that there are few times when you cannot read what they say. So if you cannot read them yourself, what about people with disabilities? I use seochat's tools almost every day and sometimes I get CAPTCHAs that should contain 5 symbols with a few blank spaces, so I must hit refresh. Aauugh.

Another way to protect your email would be by using javascript. There are a few examples to use javascript to create email links that bots will not be able to read. Some are just like the ones bellow:

<script language=JavaScript>
<!--
document.write("support" + "@" + "example.com");
//-->
</script>

<script language=JavaScript>
<!--
var user = "support";
var host = "example.com";
var link = user + "@" + host;
document.write("<a href=" + "mail" + "to:" + user + "@" + host + ">" + link + "</a>");
//-->
</script>

Another way to use javascript would be a little more complex. You can see such ways to hide large amount of information at Web International Awards (look at the Full Story button). You can use such scripts to hide your email from bots, or contact forms. To create the effect used at Web International Awards you will need an onclick action inside the IMG tag, as explained bellow:

The onclick action

onclick = "swapdisplay('a8');"  

To produce the effect you need, you must have 2 DIVs in your page. One with ID="a8a" which will be the default one, and another div with ID="a8b" which will be the div containing your email address.          

The javascript

  function swapdisplay(tag)
{
var tagA = tag + "a"
var tagB = tag + "b"

if (document.getElementById)
{
var state = document.getElementById(tagA).style.display;
}
else if (document.all)
{
var state = document.all[tagA].style.display;
}

var newStateA = "";
var newStateB = "";

if ( state == "block")
{
newStateA = "none";
newStateB = "block";

} else {
newStateA = "block";
newStateB = "none";
}


if (document.getElementById)
{
document.getElementById(tagA).style.display = newStateA;
document.getElementById(tagB).style.display = newStateB;
}
else if (document.all)
{
document.all[tagA].style.display = newStateA;
document.all[tagB].style.display = newStateB;
}
}

But what if some bots could get passed this? The DIV containing the visible data is supposed to be like style = "display:block" and the one with the contact forms or emails should be style = "display:none" , and some bots could read it.            

What next? You could try to encode your email! What? Let me explain what I mean. In a regular <a href="mailto:myemail@myemail.com">myemail@myemail.com</a> link the bot can easily read you email address. What if the link above is like explained bellow:

<a href="/img_articles/11037/ &#109;&#121;&#101;&#109;&#097;&#105;&#108;&#064;&#109;&#121;&#101;&#109;&#097;&#105;&#108;&#046;&#099;&#111;&#109;" target="_self"> &#109;&#121;&#101;&#109;&#097;&#105;&#108;&#064;&#109;&#121;&#101;&#109;&#097;&#105;&#108;&#046;&#099;&#111;&#109;</a>  

This should work wouldn't it? Yes it should. And it will probably will.  

The last, and the best way I say, would be placing a form on your contact page, where users need to input their email. They receive a link to a contact page that uses a confirmation code sent from the URL in the email they just got. The same idea of username activation. That code will be used once, and the visitor will see on the page they are taken to from their email full forms to contact you, and email addresses.  

It is up to you which one of the above you use. Personally, as soon as I have enough time I will update all of my websites using the last method, among with encoded emails in html. That will definitely get rid of my headaches.  

Conclusion

It doesn't matter how much you try to protect against spam because bots evolve and find ways to get your email. So that is why you must always update your websites in order to fight spam. If you have a break, you will get spammed.

So, is it really the time to say goodbye to spam? No. It will never be. The internet and technologies are always changing and you must keep up with them. Finish your coffee and start coding!

subscribe to newsletter