You can disable right-click inside an iframe with jQuery only when the iframe loads a page from the same origin as the parent: wait for the iframe's load event, reach into contentDocument, and bind a contextmenu handler that calls preventDefault(). If the frame points to another domain, browser same-origin policy blocks that access entirely, and no parent-side jQuery can change it. The reliable cross-origin alternative is to control the framed page itself by adding the handler to its own JavaScript or serving it with an X-Frame-Options/CSP setup that fits your needs. If you frame third-party content you don't control, right-click blocking there isn't something you can enforce from outside.

That distinction matters because "disable right click in an iframe using jQuery" gets asked as if it were one problem, and it's actually two very different problems wearing the same name. One is a short script. The other runs into a security wall that exists on purpose. This guide covers the working same-origin recipe step by step, shows how to verify it, covers the most common ways it appears to fail, and then explains honestly what your options are when the content belongs to someone else.

Why the iframe's origin decides whether jQuery can help

An iframe is a full browsing context with its own document object. Your parent page has a window, and so does the framed page; each has its own document, its own globals, and its own event targets. jQuery bundled in the parent lives in the parent's global scope. To attach a handler to the framed document, the parent script has to reach across the frame boundary and touch iframe.contentDocument. Browsers only permit that when the two documents share an origin—same scheme, host, and port.

When origins match, you have two equivalent tools: classic DOM properties like iframe.contentWindow and iframe.contentDocument, and jQuery's own cross-document selectors. When they don't match, the browser doesn't fail politely. The content document looks empty or undefined, contentWindow properties throw a SecurityError, and selectors return nothing. This is the same-origin policy doing its job, and it is not a jQuery limitation that a different version or a plugin can lift. Frames explicitly sandboxed without allow-same-origin behave the same way even when the URL looks identical, because the browser assigns them an opaque origin.

There's a second wrinkle worth naming early: even when the script works, the browser's native context menu can sometimes still appear in specific spots, and there are platform surface differences—more on both below. The short version is that "disable right click" means "suppress the contextmenu event," and suppressing an event is the only lever a page script actually has.

Prerequisites: what you need before writing a line of code

Confirm four things first, because if any is missing the recipe below won't behave as described:

1: Same origin. The framed page and the parent page load from the same scheme, host, and port—for example, both on . Subdomains don't count: www.example.com framing app.example.com is cross-origin. 2: jQuery loaded in the parent. Any supported version works; the API used here (on, contents, find, preventDefault) has been stable since jQuery 1.7. You do not need a jQuery copy inside the framed page. 3: The iframe has an identifier and is present in the DOM when your script runs. A server-rendered iframe is easiest; if it's injected dynamically, bind after insertion. 4: A way to test from the same origin in development. Serving parent and child from the same local server avoids a frustrating debug cycle where the handler silently never binds.

If the framed content is on a different domain and you can't change that, stop at this section. The later section on cross-origin options covers what actually exists.

The step-by-step recipe

The sequence below is ordered deliberately: select the frame, wait for it to load, capture the frame's document once, then bind and test. Binding before load is the single most common reason the code "doesn't work."

1: Add or identify the iframe in your HTML with a stable ID, for example . 2: Wait for the iframe's load event. Inside that handler, the framed document is parsed and its contentDocument is available. A jQuery $(function(){...}) alone only guarantees the parent DOM is ready—it says nothing about the frame. 3: Capture the frame's document once into a variable: const doc = this.contentDocument;. Store it so later code doesn't re-resolve the frame unnecessarily. this inside an iframe load handler bound with jQuery refers to the iframe element. 4: Bind the handler on the framed document. Use $(doc).on('contextmenu', function(event){ event.preventDefault(); }). This suppresses the native menu for right-clicks anywhere inside the framed document's body, including on images, links, and canvas elements inside it. 5: Optionally extend coverage to the whole window with $(doc.defaultView).on('contextmenu', ...) if your page has regions the body handler misses. For a standard page, binding to the document is usually enough. 6: Test by right-clicking an element inside the frame. The context menu should not appear; a console.log inside the handler should fire.

A complete, minimal working version looks like this:

Note the if (!doc) return; guard. It turns a silent failure into a deliberate no-op, and it's where you'd branch if you wanted to log a warning in development. The version number in the CDN tag is illustrative; use whichever supported jQuery version your project already ships.

How to check success: open the browser's developer tools console, add console.log('blocked') inside the handler, and right-click in the frame. If the log appears and no menu shows, the handler is bound to the right document. If the log appears but a menu still shows, something later in your code is unbinding or a browser extension is interfering—see troubleshooting. If neither happens, the document wasn't captured, usually because the load event fired before your binding ran, or because the origins don't match.

Covering more of the interaction surface

contextmenu is the event behind the right-click menu, and preventing it is the cleanest approach—it blocks the menu without touching the clipboard, selection, or any other behavior. Some older scripts reach for event.which === 3 or e.button === 2 to detect right-clicks; those are equivalent in effect but noisier, because they still fire the event and only filter the symptom. Prefer contextmenu with preventDefault().

Two sibling interactions often get bundled into "disable right click," and they need separate handlers on the framed document:

Dragging an image out of the frame is a dragstart event, not a context-menu event. Suppressing it requires $(doc).on('dragstart', function(e){ e.preventDefault(); }). The long-press alternative menu on touch devices still usually triggers contextmenu in modern mobile browsers, so the same handler often covers it. Test on an actual device, because behavior has shifted across mobile browser versions.

You can chain these in one place:

Neither handler changes mousedown, mouseup, or click, so left-click navigation, form inputs, scrolling, and text selection keep working. That narrowness is a feature: the less you block, the fewer legitimate behaviors you break.

Troubleshooting: symptoms and likely causes

Work from the reversible checks outward. Each item below names what you'll see and the likely cause behind it.

The menu is blocked in the parent page but not inside the frame. Your handler is bound to the parent document only. Check that you selected the iframe's document (contentDocument), not document, and that the binding runs inside the load handler.

Nothing happens at all; no console log. Either the iframe hadn't finished loading when your code ran—move the binding into the load handler—or contentDocument is null because of a cross-origin frame or a sandbox without allow-same-origin. Log this.contentDocument to tell them apart quickly.

It worked, then stopped. Common culprits: the iframe src changed (a new document needs a fresh binding—re-bind on every load event, which the recipe already does), or a script inside the framed page called event.stopPropagation() on contextmenu before it reached your document-level handler. The fix for the latter is to bind directly to the frame's document rather than relying on bubbling from inner elements, which the recipe does; if an inner element stops propagation first, you'd need to bind at the capture phase with native addEventListener('contextmenu', fn, true) inside the framed page.

A browser extension still shows a menu. Extensions can inject their own context-menu items and aren't obligated to respect page preventDefault() calls. This isn't a bug in your code and isn't fixable from the page.

Keyboard menus remain. Shift+F10 or the context-menu key trigger the same event on many platforms, so contextmenu often covers them—but not universally. Don't build assumptions about parity across operating systems without testing.

A specific spot inside the frame still shows a menu. Some embedded plugin surfaces (certain PDF viewers, native form controls, and media elements) render outside the normal DOM event path. If the element is a plugin surface rather than normal HTML, a document-level handler won't reach it.

When the frame is on another origin

Here's the part many tutorials skip, and it's the honest core of the answer: if the framed page is on a different domain, the parent's jQuery cannot touch its document, so the parent cannot block right-click inside it. You have three real options, in descending order of practicality.

Control the framed page (best). If you own both sides, put the handler directly in the framed page's JavaScript. That page's own same-origin access is unlimited, so a two-line script there works regardless of who frames it:

This requires a jQuery copy in that page, or you can do it in vanilla JS with document.addEventListener('contextmenu', e => e.preventDefault());. Either way it's simpler and more robust than any parent-side approach.

Use postMessage (workable, requires cooperation). If you control the framed page's JavaScript but not its deployment context, the parent can send a message like { type: 'disableContextMenu' } after load, and the framed page's own script applies the handler on receipt. This still needs a listener in the framed page—there's no message that makes a foreign document execute your code.

Do nothing to the frame (often correct). If you don't control the third-party content, blocking right-click inside it is generally not possible and frequently not desirable—you may also be acting against the provider's terms. No combination of jQuery options, sandbox attributes, CSS, or overlay tricks reliably suppresses the context menu inside a genuinely cross-origin frame, and attempts using transparent overlay divs either block all pointer interaction or get bypassed by keyboard and touch paths.

Situation Can parent jQuery block the frame's context menu? Practical route
Same origin (same scheme, host, port) Yes Bind contextmenu on contentDocument after load
Same host, different subdomain No Move the handler into the framed page, or serve both from one origin
Different domain, you control the framed page No, not from the parent Handler inside the framed page, or postMessage handshake
Different domain, third-party page No Not enforceable; reconsider the requirement
Sandboxed without allow-same-origin No Same as cross-origin

What the technique can't deliver, and why that's usually fine

Disabling right-click is a weak form of client-side protection, and it's worth being clear-eyed about it. Anyone who wants the image, text, or embedded URL can open developer tools, view source, read the Network tab, or disable JavaScript—preventDefault() blocks a menu, not access. It also degrades usability: users who right-click habitually to open links in a new tab, copy an address, or use a browser translation feature lose those options inside the frame. Assistive technologies that rely on context menus can be affected too, which is a real accessibility cost for a cosmetic gain.

If the underlying goal is to discourage casual copying of images, server-side controls and licensing terms do more work than an event handler. If the goal is to keep an internal tool's interface tidy, a same-origin handler is harmless and quick. The distinction is worth stating to whoever requested the feature, because "disable right click" often arrives as a request when the actual requirement is "prevent easy download of our catalog photos," and those need different solutions.

One more limit deserves mention: the handler suppresses the menu inside the frame's document, but right-clicking the iframe's border, scrollbar, or the parent page around it still produces the parent's menu unless you also handle the parent document. If you want both, bind the same preventDefault() handler to $(document) in the parent as well—and accept that this now covers the whole page.

A note on this being client-side-only code

Everything here is general front-end programming guidance with no server, legal, or safety stakes, so there's nothing to disclaim beyond the usual: verify behavior in the browsers your users actually run, since event handling around iframes and touch devices has small platform differences. If you're building this into a product where the framed content belongs to a business partner, check their terms before modifying how their page behaves inside your frame—that's a conversation, not a code problem, and it starts with confirming whose page you're actually allowed to reach into.