No one likes spam. And it seems pretty obvious at this point that if you put your email address on your website, a bot is going to find it and then start spamming you. These bots are pretty advanced and will likely figure out any scheme like "me [at] example [dot] com".
These 2 snippets of code attempt to heavily obscure the email address to hide it from email-harvesting bots. When the page loads, the Javascript function creates a bit of HTML that looks like an email address and inserts it where you want the email to appear. It will look normal to any human viewers of the site, but to a bot, best case (if the bot is also executing Javascript) your email won't appear at all, worst case, it will be much harder for the bot to parse than "me [at] example [dot] com."
Drop this HTML where you want the email address to appear:
Drop this HTML where you want the email address to appear:
<span class="dynamic-email"></span>
Edit the name
and server
variables in the code below, and then put this script block near the bottom of the page, before the closing body
tag. The first block of code assumes you have jQuery installed, the second block is plain Javascript that should work in any browser. Use either one.
<script>
$(function(){
//Assuming "yourname@example.com"... (Edit these)
let name = 'yourname'
let server='example.com'
//Don't edit this
email=name + '@' + server;
let email_display="<span>"+name+"</span><span>@</span><span>"+server;
$(".dynamic-email").html(email_display);
});
</script>
<script>
document.addEventListener("DOMContentLoaded", () => {
//Assuming "yourname@example.com"... (Edit these)
let name = 'yourname'
let server='example.com'
//Don't edit this
email=name + '@' + server;
let email_display="<span>"+name+"</span><span>@</span><span>"+server;
document.getElementByClassName("dynamic-email").innerHTML = email_display;
});
</script>