Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable drag/drop functionality in Chrome?

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?

like image 578
Shai UI Avatar asked Mar 19 '12 18:03

Shai UI


People also ask

How do I enable drag in Chrome?

Just hold on your left mouse button, performing a drag-n-drop, yeah, links open in the new tab. With CTRL button holding on, drag-n-drop, your web page will be opened in an inactive state. The drag-to-search feature is also useful and friendly to use.

How do I stop drag and drop in HTML?

Code explained: Call preventDefault() to prevent the browser default handling of the data (default is open as link on drop) Get the dragged data with the dataTransfer.getData() method. This method will return any data that was set to the same type in the setData() method.

Why can't I drag and drop into Chrome?

Fixing Drag-and-DropType "Touch" into the search bar and set the following options to "Enabled". You will have to relaunch Google Chrome for these setting changes to apply. Once you have relaunched Google Chrome, drag-and-drop gestures should now work on most compatible websites.


1 Answers

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

like image 146
Yang Avatar answered Sep 22 '22 17:09

Yang