Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

68
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!