Home > Back-end >  how to block right mouse click on iframe
how to block right mouse click on iframe

Time:05-27

How do I block the right mouse button click on top of the iframe, I tried to use the oncontextmenu="return false" in the iframe tag but it didn't work, in my case I want to change the right button on top of the pdf that I do this being a example inside the iframe, here is an example inside my code:

<html>
<head>
    <title>block the right mouse</title>
</head>
<body >
    <iframe oncontextmenu="return false" id="iframepdf" src="http://infolab.stanford.edu/pub/papers/google.pdf#toolbar=0" width="500px" height="600px" type="application/pdf"></iframe>
</body>

CodePudding user response:

This is a complete code to disable the right click

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

I Hope this is useful....

CodePudding user response:

By design an IFrame hands over the context to the users system thus you have very little control since the whole point is that it is for the users benefit.

enter image description here

  • Related