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
2 Answers
Reset to default 5You 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
版权声明:本文标题:javascript - Angular right click open also right browser menu - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744144079a2592753.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论