Search code examples
javascriptgoogle-chromemouseeventdom-events

Chrome right-click dialog swalllows mouse events


In Chrome the right-click dialog seems to swallow all mouse events. This means that you get mouse-down events without corresponding mouse-up events.

This includes every right-click, and any left-click where the right button is pressed before the left button is released (in which case you get two mouse-downs but no mouse-ups).

You can see the problem in action here (you may wish to mute your speakers) if you're curious.

I was just wondering if anyone knew of any workarounds for this? Using window.onmousedown instead of document.onmousedown doesn't fix the problem unfortunately.


Solution

  • You'll want to add a handler for the contextmenu event that cancels the opening of that menu.

    See MDN for some details.

    window.oncontextmenu = function(event) {
        event.preventDefault();
        event.stopPropagation();
        return false;
    };