How to disable right-click save on one specific image only

这一生的挚爱 提交于 2019-12-01 00:36:13

Although it's not W3C compliant, oncontextmenu="return false;" as an attribute should do exact what you want.

Stopping people altogether is futile, however, my preferred way to at least make it slightly more difficult is to place a div over the top of the image.

<div id="image-container" style="postion: relative;">
   <img src="" alt="" />
   <div style="width: 100%; height: 100%; position: absolute; top: 0; left: 0"></div>
</div>

Play around with it to get what you want. To make it seem more semantic, you could place the text in the empty div 'Image is copyright' and then do text-indent: -9999px on it. I often try and turn an empty element into something semantic.

In saying that, my favourite way to bypass people that do this (e.g. eBay) is with the plugin Nuke Anything Enhanced for Firefox. Using the div over the image trick would take me approx 2 more seconds to bypass.

If what you want is just prevent the user save your image, you can do that by using the pointer-events css property:

img {
  pointer-events: none;
}

Essentially what that's going to do is block any mouse events to img elements. You still going to get a dialog box but that is the same you get with background images.

https://developer.mozilla.org/pt-BR/docs/Web/CSS/pointer-events https://css-tricks.com/almanac/properties/p/pointer-events/

If you publish an image on the web there's no foolproof way to prevent somebody from saving a copy. It has to be sent over the wire to be displayed, and a determined user can intercept it with tools like Wireshark or Fiddler or any browser debugging framework such as Firebug, even if you find a way to disable right-click and drag-drop to the desktop.

You can make is very slightly more difficult, but the effort isn't worth it, IMHO.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!