Downsides of onMousedown vs. onClick?

21,490

One more: mousedown captures right / middle clicks too.

But for your two reasons, I would stick to onclick. I know quite a few people who use keyboard nav. Especially search-and-gotolink in FF.(/ to search followed by enter to go to the link).

But if these two are not a problem for you, I think right / middle clicks wouldn't be too.

I think the way to track all the users who follow the link is quite tricky -- the user could right click and click on new tab / new window...

Share:
21,490

Related videos on Youtube

Jack7890
Author by

Jack7890

Updated on April 14, 2021

Comments

  • Jack7890
    Jack7890 about 3 years

    I've been dealing with a bane-of-my-existence Javascript problem involving tracking when a user clicks on a link (in case you're curious, here it is: Why does using target="_blank" cause Javascript to fail?).

    I've figured out that I can solve the problem by tracking an onMousedown event rather than an onClick event.

    I'm curious about the downsides of this approach. The ones I can think of:

    1. If a user clicked down on a link and then moved the mouse off the link before releasing it, then the event would be recorded even though the user hadn't visited the link
    2. If a user used the tab key to move the browser focus to the link and then hit enter, the click would not be recorded

    Neither of these are common, so I'm not terribly worried about them.

    Are there any other downsides I'm missing?

  • Dunc
    Dunc over 12 years
    I agree with your post, but it bothers me that Google's search page uses onmousedown rather than onclick to track clicks, which suggests they handle these issues or at least consider onmousedown best practice. Any thoughts?
  • ardeee
    ardeee over 12 years
    I don't exactly know how google tracks clicks, but these are some points I can think of regarding them using onmousedown: They are interested in the aggregate click %ages - a few less or more don't matter. Using either of onclick / onmousedown, there is no reliable way to know if the user has followed a link or not (using onclick can result in missing right-click + open in new tab, using mousedown can result in every right-click being registered as a link follow). However, right click could mean the user is somehow interested in the link.
  • ardeee
    ardeee over 12 years
    Also, mousedown event gives more time to send data to Google before the link is followed (the small time difference after pressing the mouse button and before releasing it) -- enough for a request to be sent to Google's server. Not sure if onclick will leave enough time for this. The alternate option, which Yahoo does, is to first take you to their server, and then redirect you to your URL of interest.
  • Dunc
    Dunc over 12 years
    Interesting point about onmousedown allowing more time to send data back to Google - I notice Bing also does this
  • user3127648
    user3127648 about 7 years
    In short onclick event takes < 400mi/sec to fire and onmousedown takes 200mi/sec, Explained here cardinalpath.com/…