Posted on Leave a comment

How to create and protect email links

JavaScript can be used to inject an email address into the HTML page after the page has been loaded form a server. Since web crawlers do not process the JavaScript files to see their final result, this method is very effective for keeping your email safe in a web page. To explore this option, lets take a look at the JavaScript code below.

This is the code we add in the HTML head.

<script type="text/javascript"> function addEmailLink(name,domain_before,domain_after){ document.write('<a class="e-l" href="mailto:'+name+'@'+domain_before+'.'+domain_after+'">'+name+'@'+domain_before+'.'+domain_after+'</a>'); } </script>


Down in the body area we have our anchor link. What we are going to do is take our anchor link and the html code, breaking our email address into pieces and then re-injecting that content with JavaScript.

Lets see how we do this.

<script> addEmailLink('info','themerevel','com'); </script>

Now we’re injecting the email address in the href for mailto and the label area for the anchor tag. Using this approach allow us to manipulate the HTML in the browsers after the HTML has been loaded form the server.

Leave a Reply

Your email address will not be published. Required fields are marked *