How to the edit the Right-click context menu using JavaScript

357 Views Asked by At

I want to edit the context menu. When I select any text and Press the right button then this will show up.

enter image description here

I want to edit this context menu. And add the new item into this. And the exsisting buttons will be same.

In that picture "Import CURL in postman" this is embaded by the postman extension. I want to do the same thing, adding an element to the context but cann't find any solution how to do this.

1

There are 1 best solutions below

1
On

if (document.addEventListener) {
  document.addEventListener('contextmenuclick', function(e) {
    alert("hello"); //here you draw your own menu
    e.preventDefault();
  }, false);
} else {
  document.attachEvent('oncontextmenuclick', function() {
    alert("inside context menu");
    window.event.returnValue = false;
  });
}
<body>
  Lorem ipsum...
</body>