0

I am trying to prevent the standard right click menu from popping up on some information so i can display my own custom right click menu.

Right now I am getting both with the standard one appearing over the custom.

Here's my html:

<span onmouseup=\"OnRowMouseUp('Filename');\">Filename</span>

Here's my JavaScript:

var OnRowMouseUp = function (selectedField) {
    e = window.event;
    e.preventDefault();
    console.log(e);
    //this.ShowContextMenu(selectedField, e.clientX, e.clientY);
}

e is definitely a mouse event as I can view it in console. A lot of the other SO answers say that I should be using preventDefault() but it dosen't seem to be working in this circumstance. Any ideas?

Jerome
  • 734
  • 1
  • 8
  • 28
  • 1
    https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault#Blocking_default_click_handling – Estradiaz Jul 24 '19 at 22:29
  • 1
    Just an idea. There are 3 events: mousedown, click and mouseup. Maybe try experimenting with all 3 of them – Volker Andres Jul 24 '19 at 22:30
  • Possible duplicate of [Making custom right-click context menus for my web-app](https://stackoverflow.com/questions/4495626/making-custom-right-click-context-menus-for-my-web-app) – Stephen P Jul 24 '19 at 22:35

1 Answers1

2

What you're looking for is the contextmenu event.

<span oncontextmenu="OnRowMouseUp(Filename);">Filename</span>

Or

element.addEventListener('contextmenu', () => {

});

After this, preventDefault should work as expected.

Dr_Derp
  • 1,185
  • 6
  • 17