cursed Posted July 25, 2009 Share Posted July 25, 2009 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. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted July 26, 2009 Share Posted July 26, 2009 when you call an iframe, the page is loaded locally (on the clients computer) and that site will not execute your javascript. Quote Link to comment Share on other sites More sharing options...
Grayda Posted August 4, 2009 Share Posted August 4, 2009 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.