P粉3318499872023-09-04 10:54:24
There are many ways to do this. Using a reCaptcha style interceptor is probably the best option. However, here is a simple implementation that will stop most non-targeted bots.
In PHP I encoded the phone number via base64_encode and then decoded it in JavaScript using atob.
<?php function obfuscatePhone($phone){ return base64_encode($phone); } ?> <div class="contact"> <a class="btn btn-success" data-wakey="<?php echo obfuscatePhone("+212612345678");?>" target="_blank" rel="noopener noreferrer" href="#!"> More Details </a> </div> <script> const wa = document.querySelectorAll("[data-wakey]"); wa.forEach((e) => { const p = atob(e.dataset.wakey); e.href = "https://wa.me/212" + p + "?text=TextMessage"; }); </script>
The code generates this content in HTML:
const wa = document.querySelectorAll("[data-wakey]");
wa.forEach((e) => {
const p = atob(e.dataset.wakey);
e.href = "https://wa.me/212" + p + "?text=TextMessage";
});
<div class="contact">
<a class="btn btn-success" data-wakey="KzIxMjYxMjM0NTY3OA==" target="_blank" rel="noopener noreferrer" href="#!">
More Details
</a>
</div>