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

前端 未结 3 1935
无人及你
无人及你 2020-12-31 00:36

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 dr

相关标签:
3条回答
  • 2020-12-31 00:42

    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;
    }
    
    0 讨论(0)
  • 2020-12-31 00:53

    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

    0 讨论(0)
  • 2020-12-31 01:00

    Another way is to create a transparent picture over the top of the picture you want to prevent viewing.

    Please see: http://www.dwuser.com/education/content/stop-the-thieves-strategies-to-protect-your-images/

    check under "Tricking the downloaders"

    0 讨论(0)
提交回复
热议问题