obtain mouse coordinates through chrome extension

后端 未结 4 1526
夕颜
夕颜 2021-02-06 11:22

I am curious to know if there is a way to get the mouse coordinates through a chrome extension and then use these coordinates to check if the person has clicked in that position

4条回答
  •  醉酒成梦
    2021-02-06 11:41

    In my projects, I put this simple jQuery script in a separate file to check for x and y coordinates. I can simply toggle it off and on with the trackingMouse variable.

    // this lets you click anywhere on the page and see the x and y coordinates
    let trackingMouse = true;
    
    $(document).ready(() => {
      $(document).on('click', (e) => {
        if (trackingMouse) {
          let x = e.pageX;
          let y = e.pageY;
          console.log(`The x coordinate is: ${x}`);
          console.log(`The y coordinate is: ${y}`);
        }
      });
    });
    

提交回复
热议问题