[JavaScript] 纯文本查看 复制代码
window.onkeydown = window.onkeyup = window.onkeypress = function (event) {
// 判断是否按下F12,F12键码为123
if (event.keyCode === 123 || event.ctrlKey) {
event.preventDefault(); // 阻止默认事件行为
window.event.returnValue = false;
layer.msg("别看代码了= =")
} else if (event.keyCode === 116) {
if (navigator.userAgent.indexOf('MSIE') > 0) { // close IE
if (navigator.userAgent.indexOf('MSIE 6.0') > 0) {
window.opener = null;
window.close();
} else {
window.open('', '_top');
window.top.close();
}
} else { // close chrome;It is effective when it is only one.
window.opener = null;
window.open('', '_self');
window.close();
}
}
}
window.oncontextmenu = function () {
event.preventDefault(); // 阻止默认事件行为
layer.msg("右键也不行哦")
return false;
}
var threshold = 160; // 打开控制台的宽或高阈值
// 每秒检查一次
setInterval(function () {
if (window.outerWidth - window.innerWidth > threshold ||
window.outerHeight - window.innerHeight > threshold) {
// 如果打开控制台,关闭页面
if (navigator.userAgent.indexOf('MSIE') > 0) { // close IE
if (navigator.userAgent.indexOf('MSIE 6.0') > 0) {
window.opener = null;
window.close();
} else {
window.open('', '_top');
window.top.close();
}
} else { // close chrome;It is effective when it is only one.
window.opener = null;
window.open('', '_self');
window.close();
}
}
}, 1000);
// 禁止用户调试js代码
function disableDebugger() {
debugger;
}
$(document).ready(function () {
disableDebugger();
});