js禁用右键菜单选中复制剪切粘贴

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js禁用右键菜单选中复制剪切粘贴相关的知识,希望对你有一定的参考价值。

    //屏蔽右键菜单
    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;
        }
    }

    //屏蔽粘贴
    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;
        }
    }

    //屏蔽复制
    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;
        }
    }

    //屏蔽剪切
    document.oncut = 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;
        }
    }

    //屏蔽选中
    document.onselectstart = 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;
        }
    }

以上是关于js禁用右键菜单选中复制剪切粘贴的主要内容,如果未能解决你的问题,请参考以下文章

Xshell设置`左键复制右键粘贴`功能

VB在textbox中怎么禁止右键菜单中的复制粘贴功能

禁止复制,剪切,粘贴,选中,右键等功能的写法

Java Swing实现具有基本功能的记事本程序

js 禁止复制粘贴

如何禁用html中的右键菜单? [复制]