Put in the HTML link container to show your email address, where data-secret is your Base64 encoded email address. You can find plenty of websites for Base64 encoding or use JavaScript btoa function to encode your email address.
<a id="contact-link" href="#" data-secret="aGVsbG9AbXlkb21haW4uY29t">[Javascript required]</a>...<script>window.onload = function() { var contact = document.getElementById("contact-link"); contact.textContent = atob(contact.dataset.secret); contact.href = atob("bWFpbHRvOg==") + atob(contact.dataset.secret);};</script>
window.onload might not be the best choice to trigger the function, refer to cross browser dom ready.
The JavaScript will decode the Base64 encoding and generate the following output:
<a id="contact-link" href="mailto:[email protected]" data-secret="aGVsbG9AbXlkb21haW4uY29t">[email protected]</a>
Obfuscate email
To hide something, we need to encode it.
Base64
The easiet (but not the most secretive) method to encode/decode would be Base64 encoding using atob/btoa function which already exist in most browsers (minimum of IE10 required).
Reverse string
A common method to obfuscate email address is to reverse it. You can also replace @
with *
and .
with ~
.
The following function will decode moc~niamodym*tset
into [email protected]
.
<script>function decode(value) { return value.replace('*', '@').replace(/~/g, '.').split("").reverse().join("");}</script>