mootools
We all know how spammers write scripts to slurp pages and collect as many emails as they possibly can, right? Well, I've created a really easy way to avoid this problem using MooTools JavaScript. Let me show you the process.
我们都知道垃圾邮件发送者如何编写脚本来吸引页面并收集尽可能多的电子邮件,对吗? 好吧,我已经创建了使用MooTools JavaScript避免这种问题的非常简单的方法。 让我告诉你这个过程。
XHTML (The XHTML)
<a href="/david|davidwalsh.name" class="email" title="Email me.">David Walsh</a>
We create a link with the CSS class "email". The email address is inside the href attribute, but the "@" is replaced with "|". Worthless to a spammer's slurp script. The href's beginning "/" is an IE workaround.
我们使用CSS类“ email”创建一个链接。 电子邮件地址位于href属性内,但“ @”替换为“ |”。 垃圾邮件发送者的脚脚本毫无用处。 href的开头“ /”是IE解决方法。
MooTools JavaScript (The MooTools JavaScript)
$$('.email').each(function(el) {
el.set('href','mailto:' + el.get('href').replace('|','@').replace('/',''));
});
Once the DOM is ready (as always), we grab each link with the email class. We take each link's href (the modified email address) and reformat the address so that it acts as a normal email link.
一旦DOM准备就绪(一如既往),我们将获取电子邮件类的每个链接。 我们获取每个链接的href (修改后的电子邮件地址)并重新设置地址格式,以使其充当普通的电子邮件链接。
Have a better solution? Share it!
有更好的解决方案吗? 分享它!
翻译自: https://davidwalsh.name/email-protection-mootools-javascript
mootools