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

182
Vistas
How to get same ctrl+click behavior across all browsers and platforms

I'm trying to get ctrl + left mouse click to do a certain behavior, and getting different results for different browsers.

Since on mac systems ctrl+lmb is translated to right click, it seems like I have to capture the 'contextmenu' event, and then check if it is actually ctrl+lmb.

But even overcoming that, for the following script, I'm getting different results between chrome and safari.

In Chrome console I see 'Clicked ctrl + left click' on click, and in Safari I see this message twice: while ctrl is held, both when I click lmb and when I release it.

box = document.getElementById("thebox").addEventListener('click',(event) => {
    if (event.ctrlKey) {
        console.log('Clicked ctrl + left click')
        return;  
    }
    console.log('Clicked left click');
})
box = document.getElementById("thebox").addEventListener('contextmenu',(event) => {
    event.preventDefault();
    if (event.buttons === 2 || event.buttons === 0) {
        console.log("Clicked right click");
    } else if (event.buttons === 1) {
        console.log("Clicked ctrl + left click");
    }
})
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <div id="thebox" style='height: 100px; width: 100px; background-color: red;'></div>
    <script src='./index.js'></script>
</body>
</html>

I feel there should be a more simple solution to have a unified ctrl+lmb click across all browsers but can't find it, is it really that difficult?

Appreciate the help.

about 4 years ago · Juan Pablo Isaza
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