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

178
Views
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
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!