Jump to content

Disable Links Script Works, Just If Theres An iFrame.


cursed

Recommended Posts

I recently found a script that disables all the links on a page by using a loop to add onclick return false.

However, when I try to add an iFrame to the code, the script no longer works. Here's the code:

 

 

<html>
<head>
<script>
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; 
} 
</script>
</head>
<BODY bgcolor="#FFFFFF" onload="DisableEnableLinks(true)">
<a href="http://www.example.com"> This Link Is Disabled </a>


<iframe src="http://example.com" style="border: 0pt none ; left: 50px; top: -500px; position: absolute; width: 500px; height: 220px;" scrolling="no" id="sendframe" class="sendframe"></iframe>

</body>
</html>

 

 

Thanks in advance for your help.  I am truly perplexed at this problem.

  • 2 weeks later...

If the Javascript were to be run, that could cause a whole lot of security problems and possible sharing of private information

 

And just as a quick note, if you're planning to use this on a big website, I'd think twice because people could just right click the link, click "Copy Location" and paste it in to their address bar. Just thought I'd add that in ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.