semente.io cryptorave 2016


Simple JavaScript technique to prevent email spam

My efforts to reduce spam

Guilherme Gondim
2015-12-01

Spammers. They’re a scourge. Particularly loathsome is the way they use automatic programs (called robots or spiders) to crawl around the Web, “harvesting” email addresses from web pages.

That’s why this site presents email address links in a special way to defeat the nefarious robots. But this technique relies on JavaScript — which isn’t enabled in your browser.

Which is why you’ve landed on this page. This means you’ll have to enter the email address (displayed in the image below) manually into your email program.

emailaddr.png

Sorry for the extra work!

The technique

If you want to do the same on your site, here is the technique:

Instead of using the straight email in the link, as so:

<p>Send mail
    to <a href="mailto:recipient@example.net">recipient@example.net</a>.</p>

…which looks like this in the browser:

Send mail to recipient@example.net.

Use this version of the link:

<p>Send mail
    to <a onmouseover="this.href='mai'+'lto:'+'recipient'+'@'+'example.net'"
          href="antispam.html" >recipient(at)example.net</a>.</p>

…which looks like this in the browser:

Send mail to recipient(at)example.net.

That’s all there is to it! If the users’s browser doesn’t support JavaScript, the link takes them to a web page you’ll create named “antispam.html” (which is the page you are now viewing).

Good luck!