Skip to content

Instantly share code, notes, and snippets.

@paperscissors
Created May 18, 2020 23:05
Show Gist options
  • Save paperscissors/ec9cc7c478fae231aae06f23e0979b9c to your computer and use it in GitHub Desktop.
Save paperscissors/ec9cc7c478fae231aae06f23e0979b9c to your computer and use it in GitHub Desktop.
Obfuscate mailto: email links with base64 encoding and Javascript (blade file for example)
<a class="email" data-target="{{ base64_encode($email) }}" href="#">Email</a>
let elements = document.getElementsByClassName('email');
for(let i = 0; i < elements.length; i++) {
var element = elements[i];
element.onclick = function(e) {
e.preventDefault();
// converts back from base64 and launches the link
window.location = 'mailto:'+atob(e.originalTarget.dataset.target)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment