L o a d i n g . . .
主打一个C++
文章详情

html-js禁止右键菜单、复制粘贴等

Posted on 2017-07-29 20:19:24 by 主打一个C++

<script type="text/javascript">
	//屏蔽右键菜单
	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;
		}
	}
</script>


*转载请注明出处:原文链接:https://cpp.vin/page/139.html

作者近期文章
提示
×
确定
数据库执行: 8次 总耗时: 0.01s
页面加载耗时: 



wechat +447752296473
wechat cpp-blog