当用户将鼠标悬停在链接上,或者如果在移动设备上触摸它时,我的版本会从 base64 编码的电子邮件字符串动态生成链接。所有具有“data-gen-email”属性的链接都可以使用。
// The string is your base64-encoded email
const emailAddress = atob("bWFpbHRvOnlvdUBkb21haW4uY29t");
// Select all links with the attribute 'data-gen-email'
const emailLinks = document.querySelectorAll('[data-gen-email]');
emailLinks.forEach(link => {
link.onmouseover = link.ontouchstart = () => link.setAttribute('href', emailAddress);
});
您可以使用btoa('mailto:you@domain.com')
或网络上的其他地方将您的电子邮件编码为 base64 :
btoa('mailto:you@domain.com'); // "bWFpbHRvOnlvdUBkb21haW4uY29t"
html中的示例链接:
<a href="#" target="_blank" data-gen-email>Email Me!</a>