Does anyone know of a way to make an image not draggable and not selectable -- at the same time -- in Firefox, without resorting to Javascript? Seems trivial, but here's the issue:
1) Can be dragged and highlighted in Firefox:
<img src="...">
2) So we add this, but image can still be highlighted while dragging:
<img src="..." draggable="false">
3) So we add this, to fix the highlighting issue, but then counterintuitively, the image become draggable again. Weird, I know! Using FF 16.0.1
<img src="..." draggable="false" style="-moz-user-select: none;">
So, does anyone know why adding "-moz-user-select: none", would somehow trump and disable "draggable=false"? Of course, webkit works as expected. Nothing is out there on the Interwebs about this...It would be great if we could shine some light on this together.
Thanks!!
Edit: This is about keeping UI elements from being inadvertently dragged and improving usability - not some lame attempt at a copy protection scheme :-)
You could set the image as a background image. Since it resides in a
div
, and thediv
is undraggable, the image will be undraggable:I've been forgetting to share my solution, I couldn't find a way to do this without using JS. There are some corner cases where @Jeffery A Wooden's suggested CSS just wont cover.
This is what I apply to all of my UI containers, no need to apply to each element since it recuses on all the child elements.
This was way more complicated than it needed to be.
You could probably just resort to
Depending on the situation, it is often helpful to make the image a background image of a
div
with CSS.Then in CSS:
See this JSFiddle for a live example with a button and a different sizing option.
A generic solution especially for Windows Edge browser (as the -ms-user-select: none; CSS rule doesn't work):
window.ondragstart = function() {return false}
Note: This can save you having to add draggable=false to every img tag when you still need the click event (i.e. you can't use pointer-events=none), but don't want the drag icon image to appear.
Set the following CSS properties to the image: