Please put this script in the header of your website.
<script>
// Function to handle click event on mailto links
function handleMailtoClick(event) {
event.preventDefault();
const emailAddress = this.href.replace('mailto:', '');
navigator.clipboard.writeText(emailAddress)
.then(() => {
// Show an alert for one second
const alertMessage = `Email address copied: ${emailAddress}`;
alert(alertMessage);
setTimeout(function() {
const alertBox = document.querySelector('.alert-box');
alertBox.style.display = 'none';
}, 800);
})
.catch((error) => {
console.error('Failed to copy email address:', error);
});
}
// Add event listeners to all mailto links on the page
document.addEventListener('DOMContentLoaded', function () {
const mailtoLinks = document.querySelectorAll('a[href^="mailto:"]');
mailtoLinks.forEach((mailtoLink) => {
mailtoLink.addEventListener('click', handleMailtoClick);
});
});
</script>