13

Chrome browser has this weird functionality that when I drag a div, or image, it drags that item. For example, if you go to http://www.google.com you'll be able to drag that google image.

The thing is, it's messing with my javascript events. Is there a way, in javascript to disable this functionality for the chrome/safari browser?

Shai UI
  • 48,366
  • 69
  • 194
  • 298
  • Does this help -- http://stackoverflow.com/questions/704564/disable-drag-and-drop-on-html-elements – Dan U. Mar 19 '12 at 18:56

3 Answers3

12

The other answers suggesting .preventDefault() do not work for me in Chrome (v26). Had to set draggable='false' HTML5 attribute on the image. FWIW I'm using the threedubmedia drag jQuery plugin (actually the nifty newer jdragdrop reimplementation).

Yang
  • 15,457
  • 13
  • 99
  • 140
  • 1
    This makes [hammer](https://github.com/EightMedia/hammer.js/) drag and swipe events work correctly – tom Aug 07 '13 at 18:33
5

Calling

event.preventDefault();

in your event handler should disable that.

Reference

Andrew
  • 13,567
  • 13
  • 64
  • 80
0

I had the same problem when I needed to create my own drag and drop functionality. I was using mousedown, mouseup, and mousemove events. I solved it by adding event.preventDefault(); as the first line in my mousedown event handler.

tybro0103
  • 46,085
  • 33
  • 141
  • 168