分享一波:防止小白偷网页的JS代码
-
当然这些代码就是防一下小白用户~
1)干扰调试
var check = (function () { var callbacks = [], timeLimit = 50, open = false; setInterval(loop, 1); return { addListener: function (fn) { callbacks.push(fn); }, cancleListenr: function (fn) { callbacks = callbacks.filter(function (v) { return v !== fn; }); } } function loop() { var startTime = new Date(); debugger; if (new Date() - startTime > timeLimit) { if (!open) { callbacks.forEach(function (fn) { fn.call(null); }); } open = true; window.stop(); } else { open = false; } } })(); check.addListener(function () { window.location.reload(); });
2)禁用F12
document.onkeydown = function() { var e = window.event || arguments[0]; if (e.keyCode == 123) { alert('你知道的太多了!'); return false; } if ((e.ctrlKey) && (e.shiftKey) && (e.keyCode == 73)) { alert('你知道的太多了!'); return false; } if ((e.ctrlKey) && (e.keyCode == 85)) { alert('你知道的太多了!'); return false; } if ((e.ctrlKey) && (e.keyCode == 83)) { alert('你知道的太多了!'); return false; } }