首页 > 文章 > Js&Css > JS禁止F12查看源码不让电脑进行手机访问方法

禁止F12代码:

 function endebug(off, code) {
            if (!off) {
                ! function(e) {
                    function n(e) {
                        function n() {
                            return u;
                        }
 
                        function o() {
                            window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized ? t("on") : (a = "off", console.log(d), console.clear(), t(a));
                        }
 
                        function t(e) {
                            u !== e && (u = e, "function" == typeof c.onchange && c.onchange(e));
                        }
 
                        function r() {
                            l || (l = !0, window.removeEventListener("resize", o), clearInterval(f));
                        }
                        "function" == typeof e && (e = {
                            onchange: e
                        });
                        var i = (e = e || {}).delay || 500,
                            c = {};
                        c.onchange = e.onchange;
                        var a, d = new Image;
                        d.__defineGetter__("id", function() {
                            a = "on"
                        });
                        var u = "unknown";
                        c.getStatus = n;
                        var f = setInterval(o, i);
                        window.addEventListener("resize", o);
                        var l;
                        return c.free = r, c;
                    }
                    var o = o || {};
                    o.create = n, "function" == typeof define ? (define.amd || define.cmd) && define(function() {
                        return o
                    }) : "undefined" != typeof module && module.exports ? module.exports = o : window.jdetects = o
                }(), jdetects.create(function(e) {
                    var a = 0;
                    var n = setInterval(function() {
                        if ("on" == e) {
                            setTimeout(function() {
                                if (a == 0) {
                                    a = 1;
                                    setTimeout(code);
                                }
                            }, 200);
                        }
                    }, 100);
                })
            }
        }

非法调试执行的代码(不要使用控制台输出的提醒):

 endebug(false, function() {
        // 非法调试执行的代码(不要使用控制台输出的提醒)
        document.write('<body style="padding:12% 5% 5% 5%;"><div style="text-align:center;background: #3b4252;border-radius:20px;padding:30px;color: #abb9cf;width: 68%;margin: 0 auto;"><p style="font-size: 20px;">古典博客</p><p style="font-size: 20px;">禁止扒站,让你失望了!</p><p style="font-size: 20px;">关闭控制台并重新刷新页面,以便正常浏览本站内容!</p></div></body>');

禁用CTRL+S代码:

$(document).keydown(function(e){
   if( e.ctrlKey  == true && e.keyCode == 83 ){
      console.log('ctrl+s');
      return false; // 截取返回false就不会保存网页了
   }
});
((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();
});

 

网友评论