Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

256
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda