首页 🌞网站随笔

前言

在做网站美化的时候常常受到同款主题的博主扒代码

自己写的代码轻轻松松被被人一键扒去用了

本期我们介绍几种方法简单避免f12审查元素

禁用右键和f12

<script>
  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);
      }
  }
</script>

用户点击f12提示Paused in debugger

用4种方法JavaScript禁用网页右键菜单和F12审查元素防止源码被扒
将以下代码放到js文件即可

((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();
});
(function (a) {
    return (function (a) {
        return (Function('Function(arguments[0]+"' + a + '")()'))
    })(a)
})('bugger')('de', 0, 0, (0, 0));

点击f12使页面卡死

<script type="text/Javascript">
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()
    }
};
</script>

禁止右键,禁止保存网页,按下f12跳转其他页面或者关闭

<script type="text/javascript">
//禁止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就不会保存网页了
   }
});
</script>

禁止鼠标左键拖动

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;});
})



文章评论