有些網(wǎng)友為了防止網(wǎng)站被扒,會(huì)加一些限制鼠標(biāo)右鍵或者F12之類(lèi)的代碼,對(duì)新手扒站造成困擾,算是一種防護(hù)吧!也是無(wú)意中發(fā)現(xiàn)了這個(gè)代碼,感覺(jué)寫(xiě)的很全,特意分享給網(wǎng)友們!
//禁用右鍵
window.oncontextmenu = function () { return false; }
//禁止任何鍵盤(pán)敲擊事件(防止F12和shift+ctrl+i調(diào)起開(kāi)發(fā)者工具)
/* window.onkeydown = window.onkeyup = window.onkeypress = function () {
window.event.returnValue = false;
return false;
} */
//無(wú)限debugger
setInterval(function () {
check();
}, 2000);
var check = 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) { }
};
check();
//網(wǎng)站禁止選擇文字
document.addEventListener('selectstart', function (e) {
e.preventDefault();
})
document.onkeydown = function () {
//禁止ctrl+u
if (event.ctrlKey && window.event.keyCode == 85) {
return false;
}
//禁止 F12
if (window.event && window.event.keyCode == 123) {
event.keyCode = 0;
event.returnValue = false;
}
//禁止ctrl+s
if (event.ctrlKey && window.event.keyCode == 83) {
return false;
}
//禁止 F5
if (window.event && window.event.keyCode == 116) {
event.keyCode = 0;
event.returnValue = false;
}
}