반응형
Disable All Links with JavaScript
Another question that has popped up is how do I disable all of the links on the page? Well you can loop through and set the links to disabled. That in return makes them gray, but it does not disbale them.
To disable the link, you need to add an onclick and return false. If their is an onclick handler on that, you need to grab it and add it to the link. So much fun!
window.onload= function(){
DisableEnableLinks(true)
}
function DisableEnableLinks(xHow){
objLinks = document.links;
for(i=0;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;
}
Hope that helps!
http://radio.javaranch.com/pascarello/2005/05/17/1116355421179.html
Another question that has popped up is how do I disable all of the links on the page? Well you can loop through and set the links to disabled. That in return makes them gray, but it does not disbale them.
To disable the link, you need to add an onclick and return false. If their is an onclick handler on that, you need to grab it and add it to the link. So much fun!
window.onload= function(){
DisableEnableLinks(true)
}
function DisableEnableLinks(xHow){
objLinks = document.links;
for(i=0;i
//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;
}
Hope that helps!
http://radio.javaranch.com/pascarello/2005/05/17/1116355421179.html
반응형
'Know > JavaScript' 카테고리의 다른 글
window.createPopup() (0) | 2007.02.21 |
---|---|
JScript 고급개체 만들기[PROTOTYPE] (0) | 2006.07.26 |
Disable All Form Elements (0) | 2005.09.23 |