JavaScript Unspammable Email Link

I’ve come up with a JavaScript function which is good for muliple email addresses and is completely unspammable. All you need supply is the persons email name prefix and their title (or the text you want to display in the HTML page). I’m chuffed with myself because its really customizable.

I’ll do an example for my email address at work. [COLOR=Red][email protected][/COLOR]

Stick this between your HEAD tags


script language="JavaScript"
function email(name, title, subjectTitle) {
var name = name;
var title = title;
var subjectTitle = subjectTitle;
// the special characters "& # 6 4 ;" (delete the spaces between these characters, it just doesn't display on this forum thats why I did it. corresponds to the "at" sign which addresses emails to a domain. this ensured the "at" sign is never used
so spambots never realise this is an email link.
var domain = "& # 6 4 ;brakesintdotcodotuk";
domain = domain.replace(/dot/g, ".");
document.write('<a href="mailto:'+name+''+domain+'?subject='+subjectTitle+'">Email '+title+'</a>');
}
/script

and this in your BODY tags


script language="JavaScript"
email("my email prefix name", "my full name or title", "my subject")
/script

The result?

A clickable link just like normal that will display “Email the webmaster” but will not be spammable by those pesky spambots that are crawling around the net.

Hope its useful to y’all

Very nice.

But don’t get too confident. There are ways around this for email harvesters (ominous music plays in the background). So your mail address will be harvested. Probably not as much, though.

I had a more accessible solution for this (but I lost it, my hard drive crashed recently). What I did is:

I had mailto links that were formatted like this: nicholas.skehin [AT] gmail [DOT] com
I used document.links to loop through all the links
I found the ones which started with mailto:and replaced [AT] with @ and [DOT] with .

This solution is slightly more accessible, because users with JavaScript off can still use it (they just need to replace the [AT] and [DOT])