§ Avoid email harvesting with javascript
I don't like to put real email addresses on web pages because "harvesters" look for them to add to their spam list. However, harvesters probably don't run javascript before searching.
I put email addresses on pages like this:
<span class="emailaddress">"whatever at SlashbackAssociates.com"</span>
The javascript below changes it into a clickable email link in the user's browser.
The isArray() return... line probably should go all on one line, even though it seems to work fine as shown. It's so long that it misleadingly wraps if I don't break it up.
function isArray(testObject) {
return testObject
&& !(testObject.propertyIsEnumerable('length'))
&& typeof testObject === 'object'
&& typeof testObject.length === 'number';
}
function fixemails() {
var emregex = /"(.+)\sat\s(.+)"/;
var emailspans = document.getElementsByTagName("span");
for(var i=0;i<emailspans.length;i++) {
if(emailspans[i].className.indexOf("emailaddress") > -1) {
var ea=emregex.exec(emailspans[i].innerHTML);
if(isArray(ea)) {
var newem=ea[1]+'@'+ea[2];
emailspans[i].innerHTML=''+newem+'';
}
}
}
}
function makeDoubleDelegate(function1, function2) {
return function() {
if (function1)
function1();
if (function2)
function2();
}
}
window.onload = makeDoubleDelegate(window.onload, fixemails);
return testObject
&& !(testObject.propertyIsEnumerable('length'))
&& typeof testObject === 'object'
&& typeof testObject.length === 'number';
}
function fixemails() {
var emregex = /"(.+)\sat\s(.+)"/;
var emailspans = document.getElementsByTagName("span");
for(var i=0;i<emailspans.length;i++) {
if(emailspans[i].className.indexOf("emailaddress") > -1) {
var ea=emregex.exec(emailspans[i].innerHTML);
if(isArray(ea)) {
var newem=ea[1]+'@'+ea[2];
emailspans[i].innerHTML=''+newem+'';
}
}
}
}
function makeDoubleDelegate(function1, function2) {
return function() {
if (function1)
function1();
if (function2)
function2();
}
}
window.onload = makeDoubleDelegate(window.onload, fixemails);
last edited on August 19th, 2009 at 7:54 PM
Categories
Comments
- Walid on "Adventures with Ubuntu 9.10 on G4 Yikes!" - I am in the same process as you. Although I still dual-boot to Windows for my ganimg leisure. My first contact with Ubuntu was way…
- Slashback on "Simpler adding & removing element classnames" - Actually, the addClassName function does what you want, pretty much the same way you suggest.
- angie on "Simpler adding & removing element classnames" - And what if I want to add a class, but keeping the csseals the element already has?I mean, I have an element with a class, let's name…
- backlinks on "Adjust iframe height to contents" - Definitely helped me.
- Slashback on "Simpler validate form fields are filled in (no additional class names)" - You are welcome!