Incode Systems Logo Incode Systems, Inc.
www.incodesystems.com
E-mail: webmaster [at] incodesystems.com
(Last modified: Friday, July 8, 2011 6:01pm)

How to include a working mailto link with an obscured address

Including mailto: links in web pages is convenient for users to send e-mail. Unfortunately, spammers routinely harvest e-mail addresses from such links.

This mailto link hides the e-mail address from spammers using a JavaScript function. Include this function in the head tag:

<script language=JavaScript>
<!--
function mailto(mailbox,domain) {
document.location = 'mailto:' + mailbox + unescape('%40') + domain;
}
-->
</script>
Call the function like this:
<a href="javascript:mailto('webmaster','google.com')">e-mail Google Webmaster</a>

Here is a working link:
e-mail Google Webmaster


Here is another way that uses in-line JavaScript that does not require a function in the head section:

<a href="javascript:document.location=unescape('%6d%61ilto%3A')+'webmaster'+unescape('%40')+'google.com'">e-mail Google Webmaster</a>
Here is a working link:
e-mail Google Webmaster

Either method, however, requires that JavaScript be enabled on the browser. A <noscript> tag could be included on the page, if desired.