Back

 

Guibord Technical Writing Services, Inc.

 

 

 

How to protect your email address from spammers

2016 © Guibord Technical Writing Services, Inc.

 

 

To see all the information contained in this page, Java must be enabled on your PC and in your web browser.

 

Obfuscating the HTML code of an email address is a very efficient way to avoid spambots from harvesting your email address. Their software does not attempt to identify and decipher coded email addresses.  The result to time ratio would simply be prohibitive.

 

With JavaScript, you can code your email address in such a way that spambots will not decipher it.  But if Java is disabled on the PC or in the browser of your web visitor, your email address will not be displayed.  The HTML code described further in this article solves that problem.

 

JavaScript that you can copy and paste into the HTML code of your web page, where you want your email address to appear.   Simply edit the black color text to reflect your email address: 

JavaScript code for obfuscating an email address

Comments

 

<script type="text/javascript">

 

var encrypted=String.fromCharCode(109,97,105,108,116,111,58); 

 

document.write("<a href=\"");

document.write(encrypted); 

document.write("smith.john");

document.write(String.fromCharCode(30+30+4)); 

document.write("my-xyz-domain.com");

document.write("\">");

document.write("smith.john".fontcolor("red")); 

document.write(String.fromCharCode(32+32).fontcolor("red"));

document.write("my-xyz-domain.com".fontcolor("red"));

document.write("<\/a>");

 

</script>

 

 

 Begin JavaScript

 

Variable named “encrypted” defined as mailto:

 

Begin writing HTML code <a href="

Continue writing HTML code: mailto:

Begin writing recipient’s email address: smith.john

Write @ (CharCode 64 = @)

Write domain of email address: my-xyz-domain.com

Write HTML code for recipient’s email address >

Begin writing email address to appear on web page smith.john

Write @ (CharCode 64 = @)

Write domain of email address: my-xyz-domain.com

Finish writing HTML code </a >

 

End JavaScript 

 

 

Here is the result:

 

If Java is enabled on your PC and in your web browser, clicking on this email address will bring up your email application with an email ready for sending. This JavaScript produces the following HTML code, as read by all web browsers:

 

<a href="mailto:smith.john@my-xyz-domain.com">smith.john@my-xyz-domain.com</a>

 

Note: The quotation marks used in JavaScript are of the "straight quotes" type, not the smart quotes type. The ( \ ) character used in JavaScript permits the use of special characters.

 

 

HTML code to display an email address even if Java is disabled on the PC or in the browser of visitors to your web site

 

<noscript> 

 

smith.john@my-xyz-domain.com

 

</noscript>

 

 

 

HTML code obfuscating — stops spambots from harvesting your email address

 

<noscript> 

 

<span style='display:none'>@</span>smith.john<span style='display:none'>@</span>@<span style='display:none'>@</span>my-xyz-domain<span style='display:none'>@</span>.<span style='display:none'>@</span>com<span style='display:none'>@</span>

 

</noscript> 

 

With this HTML code, the obfuscated email address will be read by spambots as:

@smith.john@@@my-xyz-domain@.@com@

but will be displayed in a web browser as:

smith.john@my-xyz-domain.com

 

Such an email address can be copied directly with a mouse cursor and then pasted in an email application.

 

You can use the obfuscating character(s) of your choice; e.g., Ω instead of @

 

The goal is to make it impractical for spambots to read such email addresses, but legible and copyable by visitors to your web page.

 

 

 

Combining such Java and HTML code will display the correct email address in the browser of your web visitor. If Java is disabled, only the email address defined by <noscript> </noscript> will be displayed ; if Java is enabled, only the email address defined by the JavaScript will be displayed: 

Combining HTML and Java code

 

<noscript> 

 

<span style='display:none'>@</span>smith.john<span style='display:none'>@</span>@<span style='display:none'>@</span>my-xyz-domain<span style='display:none'>@</span>.<span style='display:none'>@</span>com<span style='display:none'>@</span>

 

</noscript> 

 

 

 

<script type="text/javascript">

var encrypted =String.fromCharCode(109,97,105,108,116,111,58);
var FamilyNameAndFirstName = "
smith.john";
var DomainName = "
my-xyz-domain.com";

document.write("<a href=\"");
document.write(encrypted);
document.write("
smith.john");
document.write(String.fromCharCode(32+32));
document.write("
my-xyz-domain.com");

document.write("\">");
document.write(FamilyNameAndFirstName.fontcolor("red"));
document.write(String.fromCharCode(32+32).fontcolor("red"));
document.write(DomainName.fontcolor("red"));
document.write("<\/a>");

</script>

 

   

Here is the result :

 

 

In other words, even if Java is disabled on the PC or in the browser of your web visitor, the correct email address will be displayed. The only difference will be that, if Java is disabled, clicking on the email address will not automatically bring up the web visitor’s email application. A copy and paste operation will have to be done, from the email address displayed to the email application.

 

You can verify this by disabling/enabling Java in your web browser. However, bear in mind that for this web page — that you are reading now — to display correctly immediately after enabling/disabling Java, you may need to refresh it twice, depending on your web browser's internal processes due to the way your web browser was engineered, not because the HTML and Java code described previously is faulty.

 

To verify this, go to another web page, switch between Java enabled and disabled in your web browser, then go back to this web page. You will see that you will not need to refresh this web page for it to display correctly.