web程序安全问题、防止别人拷走
//这段js要放在页面最下方
var h = window.innerHeight,w=window.innerWidth;
//禁用右键 (防止右键查看源代码)
window.oncontextmenu=function(){return false;}
//在本网页的任何键盘敲击事件都是无效操作 (防止F12和shift+ctrl+i调起开发者工具)
window.onkeydown = window.onkeyup = window.onkeypress = function () {
window.event.returnValue = false;
return false;
}
//如果用户在工具栏调起开发者工具,那么判断浏览器的可视高度和可视宽度是否有改变,如有改变则关闭本页面
window.onresize = function () {
if (h != window.innerHeight||w!=window.innerWidth){
window.close();
window.location = "about:blank";
}
}
//监听是否开启了调试
function isDebug() {
var threshold = 160
window.setInterval(function () {
if (
window.outerWidth - window.innerWidth > threshold ||
window.outerHeight - window.innerHeight > threshold
) {
function disableDebugger() {
debugger
}
$(document).ready(function () {
disableDebugger()
})
}
}, 1e3)
}
//移动端调试监听
function debugWeb() {
console.log(Object.defineProperties(new Error, {
toString: {value() {(new Error).stack.includes('toString@') && layer.open({
title: '请勿打开调试模式噢'
,content: '请关闭调试模式后刷新页面',
closeBtn: 0,
yes: function(){
layer.closeAll('dialog')
that.debugWeb()
}
});}},
message: {get() {layer.open({
title: '请勿打开调试模式噢'
,content: '请关闭调试模式后刷新页面',
closeBtn: 0,
yes: function(){
layer.closeAll('dialog')
that.debugWeb()
}
});}},
}));
}
未经许可,请勿转载,谢谢!