How to obfuscate an e-mail address on a website with JavaScript?

Spread the love

Sometimes, we want to obfuscate an e-mail address on a website with JavaScript.

In this article, we’ll look at how to obfuscate an e-mail address on a website with JavaScript.

How to obfuscate an e-mail address on a website with JavaScript?

To obfuscate an e-mail address on a website with JavaScript, we can use the btoa and atob functions.

For instance, we write

email = btoa("mailto:email@example.com");

to return an obfuscated version of the email address string and assign it to email.

Then we write

<a href="javascript:window.location.href = atob(email)">E-Mail</a>

to set the href attribute to set the location.href property to the email string that’s decoded with atob.

Conclusion

To obfuscate an e-mail address on a website with JavaScript, we can use the btoa and atob functions.

Leave a Reply

Your email address will not be published.