Skip to content

Instantly share code, notes, and snippets.

@tecoholic
Created July 18, 2011 06:14
Show Gist options
  • Save tecoholic/1088661 to your computer and use it in GitHub Desktop.
Save tecoholic/1088661 to your computer and use it in GitHub Desktop.
Styling and Script to disable links in a HTML page
/* The CSS styling for the class 'decolor' */
a.decolor{
text-decoration: none;
color: #000;
}
// The following in the script to disable the links in a page
// Source: http://radio.javaranch.com/pascarello/2005/05/17/1116355421179.html
window.onload= function(){
DisableEnableLinks(true)
}
function DisableEnableLinks(xHow){
objLinks = document.links;
for(i=0;i<objLinks.length;i++){
objLinks[i].disabled = xHow;
//link with onclick
if(objLinks[i].onclick && xHow){
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);
}
}
}
String.prototype.getFuncBody = function(){
var str=this.toString();
str=str.replace(/[^{]+{/,"");
str=str.substring(0,str.length-1);
str = str.replace(/\n/gi,"");
if(!str.match(/\(.*\)/gi))str += ")";
return str;
}
// The following jQuery script can be used to change the styling
$('a').addClass('decolor');
// The switching can be done by using a button with id = 'lswitch'
$('#lswitch').click(function(){
$('a').toggleClass('decolor');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment