Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable the context menu on long press when using device mode in Chrome?

How to disable the context menu on long press when using device mode in Chrome ?

I mean this context menu:

enter image description here

I am asking this because I want to debug long press gestures for mobile devices and the context menu causes my react app to behave in a strange way:

when I try to reorder the list then "strange things start to happen": selected item starts to float all over the place (as can be seen from snapshot below). The Hello World is obscured by the selected item. Really strange.

enter image description here

like image 685
jhegedus Avatar asked Dec 09 '16 12:12

jhegedus


1 Answers

I have developed a slightly more "advanced" workaround that will still (most of the time) show the contextmenu on right-click while preventing it from showing on a simulated long-tap:

window.oncontextmenu = function() {
    if (event.button != 2 && !(event.clientX == event.clientY == 1)) {
        event.preventDefault();
    }
}
like image 75
Seven Systems Avatar answered Oct 28 '22 17:10

Seven Systems