Tuesday, February 10, 2009

Disable all links using javascript

function DisableEnableLinks(xHow){
objLinks = document.links;
for(i=0;i

objLinks[i].disabled = xHow;
//link with onclick
if(objLinks[i].onclick and xHow){ //replace the and by
&&
objLinks[i].onclick = new Function("return false;" + objLinks[i].onclick.toString().getFuncBody());
}
//link without onclick
else if(xHow){
objLinks[i].onclick = function(){return false;}
}
//remove return false with link without onclick
else if(!xHow && objLinks[i].onclick.toString().indexOf("function(){return false;}") != -1){
objLinks[i].onclick = null;
}
//remove return false link with onclick
else if(!xHow && objLinks[i].onclick.toString().indexOf("return false;") != -1){
strClick = objLinks[i].onclick.toString().getFuncBody().replace("return false;","");
objLinks[i].onclick = new Function(strClick);
}


}
}

No comments: