PreventDefault blocks context menu in Firefox on Mac, but not Windows

I have a web application in which I connected the mouse and mouse down events; I use them to select and manipulate the graphic language for which my application is an editor. To prevent the right-click context menu from being displayed / context displayed by Firefox, I placed:

if (evt.preventDefault) { evt.preventDefault(); } 

at the top of each of my mouse and mouse event handlers. I do not want to return a lie; I really want the event to spread.

On a Mac, the right-click menu is not displayed; this is what i expect. However, on Windows this stubbornly appears, although Firebug confirms that my call to "preventDefault" is occurring, and also that "defaultPrevented" is set to true.

Any idea what gives? Anyone else run into this issue? I am running Firefox 6.0.2 on both Mac and Windows.

[Update: Later versions of Firefox gave consistent results on Mac and Windows: the context menu was not suppressed on both platforms.]

+4
source share
3 answers

Good. Putting this aside and returning to it several times, I finally found a solution.

An attempt to deal with the appearance of the context menu in various mouse listeners seems to be fundamentally wrong. Instead, thanks to the code I found here , I was put into the smell of the contextmenu event. This event is the correct way to handle things, although the code actually posted on this site did not do the trick - just calling "stopPropagation" and returning false was not enough.

The following worked for me:

 element.addEventListener('contextmenu', function(evt) { evt.preventDefault(); }, false); 

This has been tested with Firefox 10.0 on Mac and Firefox 9.0.1 and 10.0 on Windows 7.

+11
source

This option has been removed in the 23rd version of Mozilla.

0
source
  • Go to Tools> Options.
  • Click the "Content" tab.
  • Click the Advanced button next to Enable JavaScript.
  • Disable or replace context menus. Check this box and it will magically work again.

Cannot get around this setting in JavaScript.

-2
source

All Articles