Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

247
Views
disable text selection while right click with js?

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.

enter image description here

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report

0

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;
    }
  });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!