前端頁面禁止調試debugger方法彙總

1.打開控制檯直接跳轉頁面

<script>
    //debug調試時跳轉頁面
    var element = new Image();
    Object.defineProperty(element,'id',{get:function(){window.location.href="https://www.baidu.com"}});
    console.log(element);
</script>

2.打開控制檯,頁面內容顯示"檢測到非法調試,請關閉後刷新重試!"

<script>
        // 反調試函數,參數:開關,執行代碼
        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("檢測到非法調試,請關閉後刷新重試!");
    });

</script>
相關文章
相關標籤/搜索