0

I have tried most of the solutions to restrict the right click inside the iframe by doing a google search but am able to disable the right for the <div></div> tag but not able to restrict the right click inside the iframe window.If anybody come up with that process means share your ideas and solutions which helps me alot.This is my code

<html><head>
<script type="text/JavaScript" language="JavaScript"> 
 // http://html-generator.weebly.com/html-right-click-disable-code.html 
 var tenth = ''; 
 
 function ninth() { 
   if (document.all) { 
     (tenth); 
     alert("Right Click Disable"); 
     return false; 
   } 
 } 
 
 function twelfth(e) { 
   if (document.layers || (document.getElementById && !document.all)) { 
     if (e.which == 2 || e.which == 3) { 
       (tenth); 
       return false; 
     } 
   } 
 } 
 if (document.layers) { 
   document.captureEvents(Event.MOUSEDOWN); 
   document.onmousedown = twelfth; 
 } else { 
   document.onmouseup = twelfth; 
   document.oncontextmenu = ninth; 
 } 
 document.oncontextmenu = new Function('alert("Right Click Disable"); return false') 
</script></head><body>
 <div id="Container">
   <iframe id="fraDisabled"  src="http://www.stackoverflow.com" style="border: medium none;height: 820px;margin-left: -12px;top:55px; 
              margin: -15px 0 0 0;clip:rect(46px, 1360px, 750px, -65px);position:absolute;width: 1378px;">
    </iframe> 
  </div>
</body></html>
Sabari Karthik
  • 184
  • 3
  • 8
  • 24

2 Answers2

1

If the iframe is in the same domain you can use .contents() jQuery method.

// Grab the iframe document
var iframeEl = $('#iframeID').contents().get(0);

after getting the iframe element you can bind events to i:

// Bind event to iframe
$(iframeEl).bind('contextmenu', function(event) {
    return false;
});

If the iframe is in a different domain, jQuery won't allow it due to cross-domain request policy.

António Regadas
  • 714
  • 4
  • 11
0

It is possible if the page inside an iframe is on the same domain. While if you access the page of a different domain inside an iframe, then it is not recommended.

Reference Link: Cross Domain Policy

cheers :)

Ayon Alfaz
  • 96
  • 1
  • 6