简体   繁体   中英

How to disable oncontextmenu while rightclick dragging?

I code a webgame and I need to disable the oncontextmenu (for a rightclick mousemove issue).

On Chrome and Opera (at least), the oncontextmenu appears when you right click, mouve the mouse and release rightclick, even if you use:

<body oncontextmenu="return false;">

(this only disable immobile rightclick)

How to disable it all?

Thanks

This CSS will disable the immobile right clicks from occuring

  -webkit-user-select: none;
  /* Chrome all / Safari all */
  -moz-user-select: none;
  /* Firefox all */
  -ms-user-select: none;
  /* IE 10+ */
  user-select: none;

This JS will disable them all

document.addEventListener('contextmenu', event => event.preventDefault());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM