Steven Lu
Steven Lu

Reputation: 43417

Detect if mousedown is for a selection drag

I am tracking the mousedown state and not only does Secondary mouse button click trigger the mousedown event while failing to deliver on a mouseup event, so does the situation of dragging on something selected (note this is different from dragging to select).

I am currently experiencing this on Safari 6 on a Mac and I'll report back if I see it on other platforms/systems.

Is there a way to intercept this so that my JS program can be not confused about what's going on? For the secondary button situation I simply check event.which === 3 in my handler and just don't mark my button as down, and that takes care of that, but I am using the left button to initiate drag on a selected bit of text as well..

Upvotes: 1

Views: 861

Answers (2)

Steven Lu
Steven Lu

Reputation: 43417

The specific issue here is that mousedown is not triggered when dragging a selection.

The solution is to simply prevent selection where it may become problematic.

Upvotes: 0

Carles Andres
Carles Andres

Reputation: 1811

I am not sure I understand what you want to do, but checking which button has been pressed may involve a bit more work other that checking the which property.

Have a look this quirksmode page. The rightclick section contains some code that may help you.

A very thorough explanation on mouse events is also available here. It can really help you deal with browser quirks.

Upvotes: 1

Related Questions