Disable right click on iframe

Hello guys …
I want to disable right click on an iframe which shows an external url.
I searched the net for more than a month now and couldn’t find any solution you are my last chance …

I want to disable right click on whole page even on external iframe like this
<iframe src=“http://google.com” width=“600” height=“500”></iframe>

Is their any way?

Thanks in advanced …

Check out this page: http://www.quirksmode.org/js/improt.html

But ultimately, even this very well written script is useless, 'cause modern browsers protect its users from usability impairing scripts like disabling the right mouse button.
I, for one, have disabled such scripts in my browser preferences.

Ize Thanks for your reply …
I don’t know how to apply this to an iframe.
I want to disable right click on iframe which open an external link outside my server like google.com
do you understand me ?

I do. But I doubt if it’s possible :slight_smile:
You’re probably have to disable right click in a Javascript loaded inside the HTML page in the iframe. Which is not possible if the HTML page you’re loading comes from outside your server.

You can only disable rightclick from within the web page loaded in the frame itself.

Killing the disable script is much easier as most browsers either provide an option to do it in the browser itself or if they don’t a simple one line JavaScript run from the address bar will kill it for an individual page or you can install a userscript to kill it automatically.

felgall Thanks for your reply, I just wanted to keep newbies away from my links specially that links are out my server …
I tried to map an image on all page but it is not working too … is not their any way to select all page even with iframes inside it ?

Since “no right click” scripts only work when the browser owner gives you access to do so such scripts are rather pointless as few people will knowingly give you access to disable part of their browser and so the code will only work for newbies whose browser is configured incorrectly and who don’t know how to fix it.

[FONT=“Georgia”]Brain-storming…

What if he had one of those one-line “address bar” scripts that could be tacked on to the URL of his iframe source…[/FONT]

<iframe src=“http://google.com/ javascript:disableClick();”></iframe>

Most browsers are simply set to disallow any attempt to block access to the context menu from the web page through any means what so ever and so whatever method you try to use will be ignored and the context menu will continue to work from the right mouse button and context menu key on the keyboard as if the script were not there.

Internet Explorer is the only browser that doesn’t provide a browser setting to simply ignore all such scripts. Just makes it a mouse click or two harder to bypass in that browser (assuming that the person is using that browser and trying to access that menu for some reason).

Also most scripts only block the mouse and still leave the menu accessible from a single key press on the keyboard.

Thanks for your replies guys …
after hard search I found this code which 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>

I wonder if their is any way to get it work with external urls like google.com