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

58
Vistas
javascript event.shiftKey and event.ctrlKey give different results in different browsers on dragging event

Getting to the point

To get the point just run the provided snippet in firefox and then in chrome. In chrome the event.shiftKey will always return false.

Details

To implement the Ctrl / Alt / Shift detection, you can use the properties event.ctrlKey, event.altKey, and event.shiftKey in many event types.

This seems to work ok for Keyboard Events such as keydown / keypress / keyup.

For drag events though, there is a problem I managed to reproduce that happens ONLY in Safari browser (MAC OS).

I provide the script /snippet below. The problem is that, when I press Shift key while dragging the element, in all browsers the event.shiftKey gives "true" value. In Safari (tested on 14.01) this value is always false.

document.addEventListener("dragover", (event) => {
  var shiftKey = event.shiftKey;
  document.getElementById("div1").innerHTML = "<br>SHIFT pressed?  " + shiftKey;   
    }, false);
<div id="drag1"draggable="true">DRAG THIS TEXT WITH AND WITHOUT PRESSING SHIFT KEY<div>
<div id="div1"></div>

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