views:

415

answers:

3

Is it possible to disable right click on an iframe? I know it might be possible if the file in the iframe resides in the same domain,but i was wondering if it could be done if the file in the frame was from an external site?

thanks

+5  A: 

You can't really disable the context menu to begin with. You can only construct fragile barricades to keep people from invoking it. But the fact that this is an external iframe only compounds the issue. No, you can't keep the users from activating the context menu on your iframe. Sorry.

Jonathan Sampson
cheers for ur advice....
manraj82
A: 

works on IE to disable right click on Iframe but the problem is it does not work with external websites ,,, iframed file must be at the same domain ... take a look on it

<html>
<head>
<title>Disable Context Menu</title>
<script type="text/jscript">
  function disableContextMenu()
  {
    window.frames["fraDisabled"].document.oncontextmenu = function(){alert("No way!"); return false;};   
    // Or use this
    // document.getElementById("fraDisabled").contentWindow.document.oncontextmenu = function(){alert("No way!"); return false;};;    
  }  
</script>
</head>
<body bgcolor="#FFFFFF" onload="disableContextMenu();" oncontextmenu="return false">
<iframe id="fraDisabled" width="528" height="473" src="local_file.html" onload="disableContextMenu();" onMyLoad="disableContextMenu();"></iframe>
</body>
</html>
Dedrick
A: 

No, it's not possible if it's on an external domain. A mouse click or any other event starts at the first, topmost element it fires on and then works its way back up the chain of elements (unless propagation is stopped). If you tried to stop it at the containing document it will have already fired on the relevant elements of the child document.

Andy E