Preventing an image from being draggable or selectable without using JS

前端 未结 8 2104
忘了有多久
忘了有多久 2020-12-04 05:28

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 th

8条回答
  •  春和景丽
    2020-12-04 05:38

    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.

提交回复
热议问题