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

269
Views
How to get the x and y coordinates of mouse click on browser action context menu item

My Firefox add-on is adding a context menu to its browser action (browser toolbar button) using browser.menus.create() and specifying the “browser_action” context. This context menu item will open an extension page in its own popup window.

Is there a way to get the x and y screen coordinates of the toolbar button from where the right-click originated from? I want to be able to set the position of the popup window so that it is adjacent to the toolbar button from which the context menu item invocation happened.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Listen for the contextmenu event and get the event's pageX and pageY properties:

document.addEventListener('contextmenu', function(e){
  const xCoordinate = e.pageX;
  const yCoordinate = e.pageY;
  console.log(`x: ${xCoordinate}, y: ${yCoordinate}`)
})

about 4 years ago · Juan Pablo Isaza Report

0

You can add a listener to window/document

window.oncontextmenu = function(event){
  //get rhe x/y from the event
}

Or

document.on('contextmenu', (event)=>{
  //get the x/y from the event
})

On of them should do the trick

about 4 years ago · Juan Pablo Isaza Report

0

In VanillaJS:

document.addEventListener('contextmenu', function(event){
  var bounds = event.target.getBoundingClientRect();
  var x = event.clientX - bounds.left;
  var y = event.clientY - bounds.top;
  console.log( {x: x, y: y} );
})
about 4 years ago · Juan Pablo Isaza Report
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!