(编辑:jimmy 日期: 2024/11/16 浏览:2)
下面先看下js禁止右击保存图片。
禁止鼠标右键保存图片
<img src="/UploadFiles/2021-04-02/">禁止鼠标拖动图片
<img src="/UploadFiles/2021-04-02/">文字禁止鼠标选中
<p onselectstart="return false;">文字禁止鼠标选中</p>禁止复制文本
<p onselect="document.selection.empty();">文字禁止鼠标选中</p>jquery禁止文本复制和拷贝
$(document).bind("contextmenu copy selectstart", function() { return false; });jquery禁止图片拖拽
var img=$("img"); img.on("contextmenu",function(){return false;}); img.on("dragstart",function(){return false;});ps:js保存图片到手机相册
/保存到相册 function savePic(){ var picurl= $("#picurl").attr("src"); //alert(picurl); savePicture(picurl); }var triggerEvent = "touchstart"; function savePicture(Url){ var blob=new Blob([''], {type:'application/octet-stream'}); var url = URL.createObjectURL(blob); var a = document.createElement('a'); a.href = Url; a.download = Url.replace(/(.*\/)*([^.]+.*)/ig,"$2").split("")[0]; var e = document.createEvent('MouseEvents'); e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); a.dispatchEvent(e); URL.revokeObjectURL(url); }