您的位置:首頁技術文章
文章詳情頁

JavaScript禁止右擊保存圖片,禁止拖拽圖片的實現代碼

瀏覽:2日期:2023-06-21 11:30:13

下面先看下js禁止右擊保存圖片。

禁止鼠標右鍵保存圖片

<img src='http://www.wxshucaidpc.com/bcjs/14676.html' oncontextmenu='return false;'>

禁止鼠標拖動圖片

<img src='http://www.wxshucaidpc.com/bcjs/14676.html' ondragstart='return false;'>

文字禁止鼠標選中

<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);}

到此這篇關于JavaScript禁止右擊保存圖片,禁止拖拽圖片的實現代碼的文章就介紹到這了,更多相關js 禁止右擊保存圖片拖拽圖片內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: JavaScript
国产综合久久一区二区三区