设置页面禁止右击 禁用f12 禁止复制粘贴 回车提交表单

1.禁用F12

document.onkeydown = function() {
            if (window.event && window.event.keyCode == 123) {
                event.keyCode = 0;
                event.returnValue = false;
            }
        }

2.禁用右击

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

3.禁止复制

document.oncopy = 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;
        }
    }

4.禁止粘贴

document.onpaste = 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;
        }
    }

5.按回车键提交表单

$(document).keyup(function(event) {
        if (event.keyCode == 13) {
            $("提交按钮id").trigger("click");
        }
    });

 

以上内容部分摘自他人博客,仅用来学习与分享,感谢。

我爱玩网综合资源站,做最全最好的资源分享站点!
我爱玩网 » 设置页面禁止右击 禁用f12 禁止复制粘贴 回车提交表单