前端禁止使用F12、禁止右鍵


打開控制台直接跳轉頁面

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

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

// 反調試函數,參數:開關,執行代碼
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("檢測到非法調試,請關閉后刷新重試!");
    document.write('<h1 style="font-size:36px;color:red;text-align:center;margin-top:30vh;">檢測到非法調試,請關閉調試后刷新頁面進行閱讀!</h1>');
});

以上內容參考以下文章:

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

//禁止使用右鍵
function click(){
if(event.button==2){
alert('右鍵已經被禁用了喔!')
}
}
document.onmousedown=click;
//禁止使用F12
window.onkeydown = window.onkeyup = window.onkeypress = function (event) {
// 判斷是否按下F12,F12鍵碼為123
if (event.keyCode === 123) {
event.preventDefault(); // 阻止默認事件行為
window.event.returnValue = false;
}
};


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM