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

324
Views
CountAPI, how to register clicks from middle mouse button and the left one

This script doesn't work with the middle mouse button, only count the clicks from the left button. I want to add functionality to work with the middle one too, but how? and suggestions?

  <body>
    <a href="https://www.google.com" target="_blank" onclick="countClick('google1')">Google</a>
    <a href="https://www.duckduckgo.com" target="_blank" onclick="countClick('duckduckgo1')">DuckDuckGo</a>

    <div>Google was clicked <span id="google1_clicks">0</span> times.</div>
    <div>DuckDuckGo was clicked <span id="duckduckgo1_clicks">0</span> times.</div>
    
    <script>
      const requestHandler = async function(type, key) {
        return await fetch(`https://api.countapi.xyz/${type}/test/${key}`)
        .then(res => res.json())
        .then(res => res.value || 0)
        .catch(() => 0)
      }

      const loadClicks = (async function() {
        document.getElementById('google1_clicks').innerHTML = await requestHandler('get', 'google1')
        document.getElementById('duckduckgo1_clicks').innerHTML = await requestHandler('get', 'duckduckgo1')
      })()

      const countClick = async function(key) {
        document.getElementById(`${key}_clicks`).innerHTML = await requestHandler('hit', key)
      }
    </script>
  </body>
</html>
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!