i have a custom context menu for canvas, but with Text elements i have a problem, when i try to click on text element by right-click i have text selection (like double click).
When i use try to use:
document.addEventListener('contextmenu', (e) => {
e.preventDefault();
})
its couldn't help, because i have text selection.
It is not really "answer-worthy", but due to my low reputation, I cannot write a comment. So, that being said, you have events like "onCopy", "onCut", "onPaste", etc. You can disable each and every one of them individually. You can see an example of that here:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<h2>Copy, cut and paste disabled</h2>
<input type="text" onselectstart="return false" onpaste="return false;" onCopy="return false" onCut="return false" onDrag="return false" onDrop="return false" autocomplete=off/>
<br>
</body>
</html>
If you have any further questions - here is the full article.
Sometimes inline javascript expression is a good trick.Forexample form tags we are writing
<form id="test" onsubmit="return false;">
So I based on this example. maybe you can try this
<canvas oncontextmenu="return false;"></canvas>
edit after comments : which button actication you need excalty I dont know, but maybe you can try to find 1,2,3,4...
document.addEventListener('contextmenu', function(e) {
// forexample right-click is equal to two
if (e.button == 2) {
// Block right-click menu, thru preventing default action
e.preventDefault();
// if its not work with e.preventDefault(); add next line return false;
}
});