1

I have a button on my website that I really need to check if the user actually clicked on it (for now I am not considering accessibility or disabled people that may use other input systems). I have an onclick event handler attached to the button element.

What type of condicional can I execute on the top of the event handler so I can make sure only people who actually pressed the button using the mouse (not keyboard press) and only the mouse? I also want to detect people that fire onclick event manually from javascript console.

Is there a way I can reliably check if the mouse clicked on my button?

Note: I know there are tons of softwares that automate clicks on several OS. That's not a problem cause those automation tools execute an ACTUAL CLICK (the cursor is moved over the element and clicked). So no problem accpeting those clicks.

EDIT: the MARKED AS DUPLICATED inserted into this question has ABSOLUTELLY NOTHING TO DO WITH IT. I want to check if the onclick event was fired by human manipulating the mouse VS direct triggering/programming triggering/keyboard trigerring.

  • you can use event.type – karthick May 22 '19 at 17:12
  • @karthick event.type will only say "click" regardless how the user fired the click event. – Amanda Novaes May 22 '19 at 18:55
  • There's no foolproof way to determine who, or what, fired an event on your site. Google Analytics is basically trying to solve that problem and it is not 100% accurate. – prieber May 22 '19 at 21:23
  • Your question contains a lot of text. If you're still interested in an answer, maybe improve your question this way: write more clearly and concise (possibly as bullets) what exactly you're trying to distinguish. – DarkTrick Oct 07 '21 at 23:16

0 Answers0