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
  • 50,568
  • 73
  • 204
  • 309
  • 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
  • 16,037
  • 15
  • 100
  • 142
  • 1
    This makes [hammer](https://github.com/EightMedia/hammer.js/) drag and swipe events work correctly – tom Aug 07 '13 at 18:33
6

Calling

event.preventDefault();

in your event handler should disable that.

Reference

Andrew
  • 13,757
  • 13
  • 66
  • 84
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
  • 48,327
  • 33
  • 144
  • 170