Created
May 18, 2020 23:05
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a class="email" data-target="{{ base64_encode($email) }}" href="#">Email</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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