EmailMe

Spammers are good at their job, but we make it easy for them.

I use this piece of JavaScript on my About page to display my email address. To a viewer with eyes it's fine, but no screen scraper'll be harvest this email. No sir. The main goal is to never store the email address as a complete string that a regular expression could recognize. So, if your email address is yourself@example.com you would plug this in to a JavaScript file, and reference it in the page header.

EmailMe JavaScript


//eat this, spammers!
function emailMe(){
	var email = "<a href='mailto:yourself"
		+ "@example.com?subject=Contact from example.ca'>yourself"
		+ "@example.com</a>";
	
	document.getElementById('emailme').innerHTML = email;
}

window.onload = emailMe;

Then in the HTML you place the container span tag which is to be filled.

EmailMe HTML


<span id="emailme">[ yourself [at] example [dot] ca ]</span>

This means that someone with JavaScript turned off won't see it. I don't worry, those people are either paranoid, visit really sketchy sites, or both.

8 Comments