代码1:禁用右键和F12
我们的网页常常会被人扒源码,辛辛苦苦写的内容被人复制转账,很是苦恼,用了下面代码可以完美有效屏蔽禁用鼠标右键的菜单,同时也禁用F12审查元素功能。
在 HTML 页面中插入一段 JavaScript:
document.oncontextmenu = new Function("return false;");
document.onkeydown = document.onkeyup = document.onkeypress = function(event) {
var e = event || window.event || arguments.callee.caller.arguments[0];
if (e && (e.keyCode == 123 || e.keyCode == 116)) {
e.returnValue = false;
return (false);
}
}
代码2:F12打开后提示Paused in debugger
((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();
alert('大佬别扒了!');
document.body.innerHTML = "";
} else {
open = false;
}
}
})()).addListener(function() {
window.location.reload();
});
2.
(function (a) {
return (function (a) {
return (Function('Function(arguments[0]+"' + a + '")()'))
})(a)
})('bugger')('de', 0, 0, (0, 0));
代码3:按下F12页面卡死
function inlobase_noF12() {
while (1) {}
}
function inlojv_console() {
if ((window.console && (console.firebug || console.table && /firebug/i.test(console.table()))) || (typeof opera == "object" && typeof opera.postError == "function" && console.profile.length > 0)) {
inlobase_noF12()
}
if (typeof console.profiles == "object" && console.profiles.length > 0) {
inlobase_noF12()
}
}
inlojv_console();
window.onresize = function() {
if ((window.outerHeight - window.innerHeight) > 200) {
inlobase_noF12()
}
};
代码4:禁止右键、禁止保存网页、按下F12页面关闭或者跳转到指定页
//禁止F12
function fuckyou(){
window.close(); //关闭当前窗口(防抽)
window.location="about:blank"; //将当前窗口跳转置空白页
}
function click(e) {
if (document.all) {
if (event.button==2||event.button==3) {
alert("欢迎光临,有什么需要帮忙的话,请与站长联系!谢谢您的合作!!!");
oncontextmenu='return false';
}
}
if (document.layers) {
if (e.which == 3) {
oncontextmenu='return false';
}
}
}
if (document.layers) {
fuckyou();
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
document.oncontextmenu = new Function("return false;")
document.onkeydown =document.onkeyup = document.onkeypress=function(){
if(window.event.keyCode == 123) {
fuckyou();
window.event.returnValue=false;
return(false);
}
}
//禁用CTRL+S
$(document).keydown(function(e){
if( e.ctrlKey == true && e.keyCode == 83 ){
console.log('ctrl+s');
return false; // 截取返回false就不会保存网页了
}
});
禁止鼠标左键拖动,如果放在后面无效需要加在开头
document.onselectstart=mylock1;
function mylock1(){
event.returnValue=false;
}
禁用右键、文本选择功能、复制按键
.reader-bar为元素
$(function () {
$(".reader-bar").bind("contextmenu", function () { return false; });
$(".reader-bar").bind("selectstart", function () { return false;});
})
© 版权声明
THE END
暂无评论内容