Avatar of codequest
codequest
 asked on

Stop images from being dragged.

I'm using <input> to contain images because <inputs> don't start being dragged like <img>'s do.  

I did this in particular for a situation where a drag clone is made to appear over a static "drag template" image.  I needed to stop the static drag template image from dragging.   All in non-library javascript, which is how I want it to work.  There's a lot of custom code and variable conditions determining what can or cannot be dragged on the page.

Might there be another way to deal with this problem of images being dragged?

Any help with this would be appreciated.

Thanks!
JavaScript

Avatar of undefined
Last Comment
codequest

8/22/2022 - Mon
Big Monty

if you can put a div around the images, you can then do something like this:

<div id="myDiv" onmousedown="return false;">
   <img src='abc.gif' />
<div>

To totally protect images, watermark them. As soon as you display them on your page and someone visits it, it's been downloaded, so any script won't protect an image.
codequest

ASKER
Thanks the input.   I tried variations on this:

<div id="GR_BA999" onmousedown = "return false;">
<img src="../../App_Images/DnDNewBoundary.BMP" alt="" width="35px" height="20px" onmousedown = "return false;"/>
</div>

Open in new window


However none of that stopped the image drag.   Here's a more complete description of the situation, and also a solution to that immediate problem.

http://stackoverflow.com/questions/14025892/drag-and-drop-with-clone-produces-circle-slash

I was hoping for something simpler because putting the image in an input has side effects.
Big Monty

not 100% sure, but I don't think you're suppose to have spaces in a tags attribute, so change

<div id="GR_BA999" onmousedown = "return false;">

to

<div id="GR_BA999" onmousedown="return false;">
Your help has saved me hundreds of hours of internet surfing.
fblack61
codequest

ASKER
Thanks for input.  Tried it: no change in behavior.
Big Monty

not sure then, as that really should work. I would suggest click the Request Attention feature to see if there other experts who may be able to help.
ASKER CERTIFIED SOLUTION
Robert Schutt

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
codequest

ASKER
Thanks for the input. The ondragstart = "return false;" worked.  Big help.   That gives me more flexibility  And, it also worked inside the div, so more flexibility still.

I appreciate the comments on copying images;  that was not the concern.  The images in question are little diagram graphic icons, nothing special about them.

These graphics sit in header bar at the top of the diagram space, where they can be dragged (via a clone) onto the diagram.  The issue was that between the time I would mousedown on the "static/non-moving" graphic, and the time that the drag clone was positioned and made visible, the system would start dragging the static graphic, which would interfere with the drag clone operation.

Nice to get that fixed without having to make the static graphics into inputs.  Grazie!
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.