Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downsides of onMousedown vs. onClick?

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?

like image 673
Jack7890 Avatar asked Oct 28 '09 06:10

Jack7890


People also ask

What is the difference between Mousedown and click?

Note: This differs from the click event in that click is fired after a full click action occurs; that is, the mouse button is pressed and released while the pointer remains inside the same element. mousedown is fired the moment the button is initially pressed.

Is Onclick case sensitive?

As we know, HTML attribute names are not case-sensitive, so ONCLICK works as well as onClick and onCLICK … But usually attributes are lowercased: onclick .

What is the use of Onmousedown?

The onmousedown attribute fires when a mouse button is pressed down on the element. Tip: The order of events related to the onmousedown event (for the left/middle mouse button): onmousedown. onmouseup.


1 Answers

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...

like image 149
Raze Avatar answered Sep 18 '22 15:09

Raze