本文对开发者模式禁用提供了五种处理方案
禁用右键、定时器增加debugger、监视DOM修改、监听可视高度修改、禁用F12
禁用右键 (防止右键查看源代码、作用不大)
document.oncontextmenu = function () { return false; };
定时器增加debugger
setInterval(function () {
function doCheck(a) {
if (("" + a / a)["length"] !== 1 || a % 20 === 0) {
(function () { } ["constructor"]("debugger")())
} else {
(function () { } ["constructor"]("debugger")())
}
doCheck(++a)
}
try {
doCheck(0)
} catch (err) { }
}, 1000);
监视DOM修改
window.addEventListener("DOMCharacterDataModified", () => window.location.reload(), true);
window.addEventListener("DOMAttributeNameChanged", () => window.location.reload(), true);
window.addEventListener("DOMCharacterDataModified", () => window.location.reload(), true);
window.addEventListener("DOMElementNameChanged", () => window.location.reload(),true);
window.addEventListener("DOMNodeInserted", () => window.location.reload(), true);
window.addEventListener("DOMNodeInsertedIntoDocument", () => location.reload(),true);
window.addEventListener("DOMNodeRemoved", () => window.location.reload(), true);
window.addEventListener("DOMNodeRemovedFromDocument", () => location.reload(),true);
window.addEventListener("DOMSubtreeModified", () => window.location.reload(), true);
判断可视高度和可视宽度是否有改变,如有改变则刷新页面
var h = window.innerHeight, w = window.innerWidth;
window.onresize = function () {
if (h != window.innerHeight || w != window.innerWidth) {
window.location = "https://www.s.51.com";
}
};
禁用F12
document.onkeydown=function(){
if(window.event&&window.event.keyCode==123){
event.keyCode=0;
event.returnValue=false;
}
}
版权声明:本文为CodingmanNAN原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。