javascript - Angular right click open also right browser menu - Stack Overflow

I'm trying to add the right click in my ponent. The piece of code is here:(contextmenu)="open

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();
    ...
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744144079a4560339.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信