Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

260
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda