JavaScript禁止右擊保存圖片,禁止拖拽圖片的實現(xiàn)代碼
下面先看下js禁止右擊保存圖片。
禁止鼠標右鍵保存圖片
<img src='http://www.cgvv.com.cn/bcjs/14676.html' oncontextmenu='return false;'>
禁止鼠標拖動圖片
<img src='http://www.cgvv.com.cn/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禁止右擊保存圖片,禁止拖拽圖片的實現(xiàn)代碼的文章就介紹到這了,更多相關js 禁止右擊保存圖片拖拽圖片內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持好吧啦網(wǎng)!
