Mailnull Logo

Create Free Account


Secure request. Lock

Search this site

Javascript Email Address Obfuscation
How to Hide Your Address

We all need to better protect our email addresses. Spam robots and other agents crawl the web looking for exposed mailto links and other email addresses in the clear. One way to hide your address is to use javascript to encode your email addresses. Although this may only slow down the robots, it seems to be currently effective (July 2006).

So make it work, you put a script into your page (usually in <head>) and then use the script when you want to spit out a mailto: link. The script is:

<script language="JavaScript">
  function myMailto(user, host) {
	e = user + "@";
	for (i = 0; i < host.length - 1; i++) { e = e + host[i] + "."; }
	e = e + host[host.length - 1] ;
	document.writeln("<a href='mailto:" + e + "'>" + e + "</a>");

when you want to use it, you call it like:

<script language="JavaScript"> myMailto("foo", [ "bar","com" ]); </script>

This generates:

NOTE: It may be only a matter of time until the spam harvesters start processing javascript.

For more details, see the pages on how to protect your email address.

Please consider donating money to the cause, putting a link to us on your page, and spreading the word about MailNull.
Copyright 2018 by Gray Watson

Free Spam Protection   Eggnog Recipe   Android ORM   Simple Java Magic   JMX using HTTP   OAuth 2.0 Simple Example   Great Eggnog Recipe   Christopher Randolph