Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stop Chrome's click and hold / drag image default behavior

Tags:

I've noticed that in Google Chrome, one can click and hold an image and while holding a semi-transparent copy of that image attaches itself with the cursor. Then one can drag that image to the desktop to save it.

I want to prevent and stop the semi-transparent version of the image attaching itself to the cursor on hold of certain images in my site.

How can I do this?

like image 977
Irfan Mir Avatar asked Apr 29 '13 15:04

Irfan Mir


People also ask

How do I turn off drag image?

Setting the draggable HTML Attribute to false We can also set the draggable HTML attribute of the img element we want to disable dragging for to false . to disable dragging. To do the same thing with JavaScript, we can use the setAttribute method: const img = document.

How do you make an image not draggable in CSS?

if you add draggable="false" to the image tag, it will stop being draggable.

Why is drag and drop not working on 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.

How do I drag and drop 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.


2 Answers

You can prevent this behavior by using the property

-webkit-user-drag: auto | element | none; 

See the doc of -webkit-user-drag CSS-infos.net (I didn't find an MDN doc, if someone has a better reference)


How to use

Add a .nonDraggableImage class on your img tags, and add on your CSS :

.nonDraggableImage{     -webkit-user-drag: none; } 
like image 190
Bigood Avatar answered Nov 24 '22 07:11

Bigood


I had to use a different solution to get it working:

<img src="http://placehold.it/150x150" draggable="false"> 

Thanks: https://stackoverflow.com/a/7439078/2443005

like image 39
BBlackwo Avatar answered Nov 24 '22 07:11

BBlackwo