§ 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
- Slashback on "window.onload via double delegate function" - The makeDoubleDelegate() function is rather simple and straightforward, so I find it quite odd that Chrome can't handle it. I do…
- Joaquin Serra on "window.onload via double delegate function" - Hello, i'm using this function one year but i realized now that in Google chrome doesn't work. Have you got some solution?
- tadd on "Javascript function to add css" - thanks for the post
- Slashback on "window.onload via double delegate function" - The makeDoubleDelegate function just needs to be available, so include it once somewhere in your html file or an included javascript…
- Neil Haskins on "window.onload via double delegate function" - I don't understand exactly how this is to be used; I've just used javascript in a cut and paste manner really. Does the whole code go…