# JavaScript Unspammable Email Link

**URL:** <https://forum.kirupa.com/t/javascript-unspammable-email-link/56108>\
**Category:** web dev\
**Created:** [June 30, 2004, 3:51pm UTC](https://forum.kirupa.com/t/javascript-unspammable-email-link/56108 "2004-06-30T15:51:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![as\_clark20](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@as\_clark20](https://forum.kirupa.com/u/as_clark20)\
**Post date:** [June 30, 2004, 3:51pm UTC](https://forum.kirupa.com/t/javascript-unspammable-email-link/56108/1 "2004-06-30T15:51:49Z")

</div>

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]adam@dataworks.org.uk[/COLOR]

Stick this between your HEAD tags

```auto

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

```auto

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 3, 2004, 10:07am UTC](https://forum.kirupa.com/t/javascript-unspammable-email-link/56108/2 "2004-07-03T10:07:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 3, 2004, 10:22am UTC](https://forum.kirupa.com/t/javascript-unspammable-email-link/56108/3 "2004-07-03T10:22:24Z")

</div>

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])
