View Full Version : Access context menu in iframe

22 Nov 2007, 11:57 AM
I want to overide the default browser context menu in an iframe. The following code works in IE, but not FF. In FF the alert is never displayed.

window.frames["center-iframe"].document.oncontextmenu = function(){ alert("No way!"); return false; };

as does:

document.getElementById("center-iframe").contentWindow.document.oncontextmenu = function(){ alert("No way!"); return false;};;

I have no trouble doing this outside the frame. The frame is in a borderlayout center region if that matters.


<iframe id="center-iframe" name="center-iframe" frameborder="0" oncontextmenu="return false;" scrolling="auto" style="border:0px none; height:100%; width:100%;" ></iframe>


Ext.get("center-iframe").swallowEvent( "contextmenu", true );

work in IE or FF. I appreciate this isn't strictly an ExtJS issue. I've Google'd to no avail so far.