这里写自定义目录标题
页面图片防复制
1.css
img {
pointer-events:none;
-webkit-touch-callout:none; /*系统默认菜单被禁用*/
-webkit-user-select:none; /*webkit浏览器*/
-khtml-user-select:none; /*早期浏览器*/
-moz-user-select:none;/*火狐*/
-ms-user-select:none; /*IE10*/
user-select:none;
}
2.js
// 防止F12调试
setInterval(function(){
check();
}, 2000);
var check = function(){
function doCheck(a){
if (('' + a / a)['length'] !== 1 || a % 20 === 0){
(function() {
alert(11)
}['constructor']('debugger')());
} else {
(function() {
alert(22)
}['constructor']('debugger')());
}
doCheck(++a);
}
try {
doCheck(0);
}catch(err){}
};
check();
// 阻止鼠标右键和复制
document.oncontextmenu = function(){
return false;
}
document.onkeydown = function(){
if (event.ctrlKey && window.event.keyCode==67){
return false;
}
}
document.body.oncopy = function (){
alert('对不起,本网页禁止复制!')
return false;
}
// 移动端禁用复制
var imgArr = $('img')
$.each(imgArr,function(i) {
// 移动端隐藏原来的img标签
imgArr.eq(i).css({
'display': 'none'
})
// 构建div 把img的src设置为背景图
var imgModal = '<div class="imgBg" style="width:100%;height:100%;background-image:url('+imgArr.eq(i).attr('src')+');background-size:100%;"></div>'
imgArr.eq(i).parent().append(imgModal)
})
// 移动端阻止图片复制
var Timer = null
$(document).on("touchstart",".imgBg", function(e){ //这里使用touchstart事件也可以
e.stopPropagation();
Timer = setTimeout(function(){
alert('禁止复制')
return false
},400)
// e.preventDefault();
});
$(document).on("touchmove", ".imgBg", function(e) {
clearTimeout(Timer);
})
$(document).on("touchend", "..imgBg", function(e) {
clearTimeout(Timer);
})
}