简体   繁体   中英

Is there a function that makes an image not clickable so that the default chrome widget doesn't appear and allow them to download the image?

是否有使图像不可点击的功能,以便不会出现默认的 chrome 小部件并允许他们下载图像?

You could just add it onto a canvas which makes the image unclickable:

HTML

<canvas id="myCanvas">
<img id="image"src='https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/SNice.svg/220px-SNice.svg.png'>

Javascript

window.onload = function() {
  var c = document.getElementById("myCanvas");
  var ctx = c.getContext("2d");
  var img = document.getElementById("image");
  ctx.drawImage(img, 10, 10);
};

CSS

 body { -webkit-user-select: none; /* Chrome all / Safari all */ -moz-user-select: none; /* Firefox all */ -ms-user-select: none; /* IE 10+ */ -o-user-select: none; user-select: none; }

JS

 <script> document.addEventListener('contextmenu', event => event.preventDefault()); </script>

HTML

 <body oncontextmenu="return false;">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM