admin管理员组

文章数量:1396878

I'm trying to add the right click in my ponent. The piece of code is here:

(contextmenu)="openNote(i)"

that open a popup.

The problem is that when I click with right click it's work fine(the popup is opened) but there is also called the right click of browser(with 'back', 'refresh',...).

How can I disabled the browser right click when I click my function?

I'm trying to add the right click in my ponent. The piece of code is here:

(contextmenu)="openNote(i)"

that open a popup.

The problem is that when I click with right click it's work fine(the popup is opened) but there is also called the right click of browser(with 'back', 'refresh',...).

How can I disabled the browser right click when I click my function?

Share Improve this question asked Jul 2, 2019 at 15:28 travis_911travis_911 3218 silver badges22 bronze badges 1
  • 1 Capture the onContextMenu event, and return false in the event handler. – Patrik Alexits Commented Jul 2, 2019 at 15:31
Add a ment  | 

2 Answers 2

Reset to default 5

You need to return false from the method openNote.

So if your code is something like:

<app-myComponent (contextmenu)="onRightClick($event)"></div>

You need to have the following openNote method:

 onRightClick(event) {
    // Your code here
    ...
    return false;   // Add return false
 }

Return false avoid the default browser action for the event right click.

You need to prevent event default behaviour first.

html:

(contextmenu)="openNote($event, i)"

.ts

openNote($event, i) {
    $event.preventDefault();
    ...
}

本文标签: javascriptAngular right click open also right browser menuStack Overflow