HTML 屏蔽F12及右键的通用方法

Tony哥
2023-08-25 / 0 评论 / 139 阅读 / 正在检测是否收录...
<h1>HTML 屏蔽F12及右键的通用方法</h1>
<script type="text/javascript">
    //禁用F12
    window.onkeydown = window.onkeyup = window.onkeypress = function (event) {
        // 判断是否按下F12,F12键码为123
        if (event.keyCode == 123) {
            event.preventDefault(); // 阻止默认事件行为
            window.event.returnValue = false;
        }
    }
    //屏蔽右键菜单
    document.oncontextmenu = function (event) {
        if (window.event) {
            event = window.event;
        }
        try {
            var the = event.srcElement;
            if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
                return false;
            }
            return true;
        } catch (e) {
            return false;
        }
    }
</script>
1

评论 (0)

取消