1

I have right-click disabled in the header of a website using

<body oncontextmenu="return false">

Which gives the functionality that I have been asked for.

But I have a requirement to then re-enable right click on an iframe within this site and I'm not sure this is possible.

Without going into the "Why?", "Don't bother", etc... comments, I was wondering if someone could kindly answer if (or not) this will be possible, and how?

On the iframe I have tried to give it it's own <body> tag, but the main parents <body oncontextmenu="return false"> tag seems to be overriding it.

Edit :

This line is in the parent page <body oncontextmenu="return false"> The iframe is on a different domain to the parent page.

omega1
  • 1,031
  • 4
  • 21
  • 41
  • Are you accessing the iframe from the parent page? Is this body tag from the parent page? Or is that body tag from the child page within the iframe? If so, is the child page on the same domain? – zer00ne Jan 05 '16 at 13:19
  • is the iframe page in the same origin? – Daniel A. White Jan 05 '16 at 13:21
  • Hello, thank you. They are on different domains (which I administer). Adding clarification in the question. – omega1 Jan 05 '16 at 14:07

2 Answers2

1

If you are in the same domain, you can use jquery like this:

HTML

<iframe id="iframeID" src="/your_page.html"></iframe>

JAVASCRIPT

    $(document).ready(function () {
        $('#iframeID').load(activeContextMenu);
    });

    function activeContextMenu() {
        $('#iframeID').contents().find('body').attr('oncontextmenu', '');
    }
Baro
  • 5,300
  • 2
  • 17
  • 39
0

Below SO answer should work, including an alternative to disabling it in the html and flexibility for different browsers.

https://stackoverflow.com/a/2405835/5741308

Community
  • 1
  • 1
S.Pote
  • 71
  • 1
  • 5