OnMousedown disadvantages vs onClick?

I was dealing with a Javascript problem that is tracking when a user clicks on a link (in case you are interested, here it is: Why does using target = "_blank" cause Javascript to crash? ).

I realized that I can solve the problem by tracking the onMousedown event, not the onClick event.

I am curious about the disadvantages of this approach. The ones I can think of:

  • If the user clicked on the link and then moved the mouse from the link before it was released, then the event will be recorded even if the user has not visited the link
  • If the user used the tab key to move the browser focus to the link, and then press the enter key, the click will not be recorded.

None of them are common, so I don’t really care about them.

Are there any other shortcomings that I am missing?

+6
javascript javascript-events onmousedown onclick
source share
1 answer

One more thing: mousedown captures right / middle clicks too.

But for your two reasons, I will stick with onclick. I know a lot of people who use the nav keyboard. Especially search-and-gotolink in FF. (/ To search, then enter to go to the link).

But if these two are not a problem for you, I think that right / middle clicks will not be too much.

I think the way to keep track of all the users that follow the link is rather complicated: the user can right-click and click on a new tab / new window ...

+6
source share

All Articles