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

57
Visualizações
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 à 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