Closed Bug 72084 Opened 23 years ago Closed 23 years ago

There is no way to disable the context menu upon right-click (oncontextmenu?)


(Core :: DOM: UI Events & Focus Handling, defect)

Not set





(Reporter: bcortez, Assigned: hyatt)




Currently, is there any way to completely disable the right-click context menu 
in the Mozilla browser? For Mozilla to be a valuable business application 
platform, application developers need a JavaScript event handler exposed to 
disable the display of the context menu.  This would prevent users from 
inadvertantly opening the current application in a new browser window....which 
could have serious side-effects in a stateful application model.

NOTE: MSIE currently exposes the 'oncontextmenu' event which can be used to 
disable the display of the context menu. A simple call such as:

   document.oncontextmenu = function(){return false};

accomplishes this task.
There are loads of javascrips doing this.

Here's one working with Mozilla
On a further comment, document.oncontextmenu is a proprietary feature of
internet explorer
This code snippet does not fully work in Mozilla/Netscape 6.  IT only half 
works...let me explain.  

When you right-click on the document, the context menu appears, then a 
JavaScript alert box appears.  The side-effect of the alert box appearing is 
that it seems to cancel the context menu (and it disappears).  However, if you 
mouse over the context menu as soon as it appears (prior to the alert box), 
once the alert box appears, the context menu stays displayed and is fully 

Therefore, there is no way to truly disable the display of the context menu in 
Mozilla/Netscape 6 as I originally stated.

ccing mpt to see what he says
What bcortez describes about the context menu displaying briefly is another bug. 
 I remember reading it, but I can't remember what it was (and I'm at work).

The keeping open of the context menu was related to bug 45108 and fixed the 
other day.  It just hasn't made it to the servers yet due to the internal 
Cc ianh and bob clary.  

See also

agreeing with this bug:
 bug 28604 [DOM] Context menu should wait for onclick / onmousedown handler
 bug 60889 handler doesn't get called if context-menu is active onClick

disagreeing with this bug:
 bug 14716 [RFE] don't popup new windows while mouse button is down 
 bug 40535 [RFE] disallow/queue alert (and on right-click
Summary: There is no way to disable the context menu upon right-click → There is no way to disable the context menu upon right-click (oncontextmenu?)
Also related: bug 71705, Right-click triggers onclick handler.
Bug 36665 may be related, or at least in a related area dealing with the 
context menu.
there is now an oncontextmenu event. js handlers can call event.preventDefault() 
and the context menu will never fire.

--> hyatt so he gets credit on his p4.
Assignee: joki → hyatt
Closed: 23 years ago
Resolution: --- → FIXED
<quote src="bug 28604" author="me">
IMO, it is none of the business of a webpage to mess with context menus in any
way. Sometimes (e.g. after a or when I minimize the normal chorme),
the context menu is my only way to interact with the app. E.g. to access "View
Source" or to specify how to open a link or anything. A webpage must not be
allowed to interfere with my ability to do so.

I have seen pages that tried to prevent me from looking at the source. This must
not happen.

In this case, a don't care about any W3C spec. This is basic usability. At the
very least, I must have the option (with UI) to disallow such malicious
behaviour of webpages. Everything else is IMO a serious bug.

  I understand your concern and the reasoning behind your statements, however, 
for Mozilla to be seriously considered (and truly compete) as an enterprise 
platform for real web-based applications this is a necessity.  Not for the sake 
of preventing the "view source" action, but for other more concrete reasons 
like mulithreading issues surrounding JAVA applets as one example.

  For a more through discussion, I suggest we take this offline.  I wouldn't 
like to burden the recipients of this list with undue/off-topic emails.

bcortez, the discussion, if a bug should be fixed or not is ontopic to a bug.
Nevertheles, I agree that newgroups are more approriate. Posted to .dom
QA contact updated
QA Contact: gerardok → madhur
Filed bug 86193 for option to revert the behaviour implemented in this bug.
verified on build 2001-07-30-10-trunk
*** Bug 73981 has been marked as a duplicate of this bug. ***
*** Bug 97600 has been marked as a duplicate of this bug. ***
*** Bug 98191 has been marked as a duplicate of this bug. ***
I think it is a good think oncontextmenu is now available in Mozilla, but I also
understand people who hate sites blocking the general context menu without any
reason but blocking access to viewsource etc.

Maybe it would be a good idea to make something like an "Allow webpages to
replace or block context menu" option in Preferences -> Advanced -> Scripts &
Windows ?
Is there currently a prefs.js cheat available to disable websites from blocking
the context menu?
Simon: Not AFAIK. You're probably thinking of bug 86193.
*** Bug 160611 has been marked as a duplicate of this bug. ***
*** Bug 169290 has been marked as a duplicate of this bug. ***
Component: Event Handling → User events and focus handling
You need to log in before you can comment on or make changes to this bug.