Pitfall
You can not put
document.onselectstart = function(){ return false; };
to your mousedown handler because onselectstart is already running.
Decision
So for it to work, you need to do this before the mousedown event. I did this in the mouseover event, since as soon as the mouse enters my element, I want it to be dragged, not selected. Then you can put
document.onselectstart = null;
call the mouseout event. However, there is a catch. While dragging, you can trigger the mouseover / mouseout event. To counter this, in your dragging / mousedown event, set the dragging flag to true and set it to false when dragging the stops (mouseup). Mouseout function can check this flag before setting
document.onselectstart = null;
Example
I know that you are not using any library, but here is a jQuery code example that may help others.
var flag_dragging = false;//counter Chrome dragging/text selection issue $(".dragme").mouseover(function(){ document.onselectstart = function(){ return false; }; }).mouseout(function(){ if(!flag_dragging){ document.onselectstart = null; } }); //make them draggable $(".dragme").draggable({ start: function(event, ui){ flag_dragging = true; }, stop: function(event, ui){ flag_dragging = false; } });
Finch_Powers Oct 13 '11 at 10:14 2011-10-13 22:14
source share