meandeviation.com > obfuscate email

simple email obfuscation

 
Alan Dix
http://www.hcibook.com/alan

This page uses a simple JavaScript function to construct mail addresses "on the fly" as the page is rendered on the web browser's screen. It uses the "document.write" method, which is works on all browsers except very ancient ones (it is the same method used for syndicated content). This will prevent web harvesters from finding the email addresses and using them for spamming.

Here is an example of its use.

Alan Dix
Peter Pan
Wizard of Oz
Dr Who

If you use "View Source" you will see that there are no bare email addresses so web harvesters cannot find the addresses. However, the addresses can be cut and pasted by a human user or (where this is specified) clicked as live links to open a mail message in your default mailer (assuming your browser is setup to deal with "mailto" links correctly).

A single JavaScript function email_addr(name,host,isLink,otherName) needs to be declared at the beginning of the script. This is then called where an email address is needed on the page. It takes two arguments the email name and the host (e.g. "alan", "hcibook.com"). It simply inserts the "@" between them. An optional third argument specifies that the mail address be a live "mailto:" link. A final (again optional) otherName argument gives alternative text to be used as the link instead of the mail address itself.

The code for each example above is as follows:

Alan Dix
<script language="JavaScript"> <!--
    email_addr("alan","hcibook.com",1);
//--></script>
isLink=1 makes live link with "mailto:"
Peter Pan
<script language="JavaScript"> <!--
    email_addr("pp","hollowtree.nnl",0);
//--></script>
isLink=0 means link is not live
Wizard of Oz
<script language="JavaScript"> <!--
    email_addr("wizard","emerald.city.oz"); 
//--></script>
missing last argument defaults to no live link
Dr Who
<script language="JavaScript"> <!--
    email_addr("professor",
	      "tardis.gallifrey.plan",1,"Dr Who"); 
//--></script>
added otherName argument

The code to insert in the header is as follows (use "View Source" to see it on this page).

<script language="JavaScript">
<!-- // code by Alan Dix © 2004 http://www.meandeviation.com/
// you are free to use, copy, or distribute this code so long as this notice
// is included in full and any modifications clearly indicated function email_addr(name,host,isLink,otherName) { var email = name + "@" + host; var linktext = email; // text to display within link if (otherName) { linktext = otherName; isLink = 1; // only makes sense for live link } if ( isLink ) document.write("<a href=\"mailto:" + email + "\">"); document.write(linktext); if ( isLink ) document.write("</a>"); document.close(); } //-->
</script>

http://www.meandeviation.com/utils/obfuscate/ Alan Dix © 2004