zxk5211

禁止右键菜单 || 禁止键盘事件

1、禁止鼠标右键菜单

// 屏蔽鼠标右键菜单
document.oncontextmenu = function () {
		return false;
};
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<link rel="icon" href="/favicon.ico" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Vite App</title>
	</head>
	<!-- 禁用鼠标右键菜单 -->
	<body oncontextmenu="self.event.returnValue = false">
		<div id="app"></div>
		<script type="module" src="/src/main.js"></script>
	</body>
</html>

2、禁止键盘按键事件

window.onload = function () {
	document.onkeydown = function () {
		let e = window.event || arguments[0];
		if (e.keyCode == 123) {
			return false;
		} else if (e.ctrlKey && e.shiftKey && e.keyCode == 73) {
			return false;
		} else if (e.ctrlKey && e.keyCode == 85) {
			return false;
		}
	};
	// 屏蔽鼠标右键菜单
	document.oncontextmenu = function () {
		return false;
	};
};

分类:

技术点:

相关文章:

  • 2021-11-06
  • 2022-12-23
  • 2021-11-23
  • 2021-06-24
  • 2021-10-06
  • 2021-06-17
  • 2022-12-23
猜你喜欢
  • 2022-01-09
  • 2021-12-06
  • 2021-12-06
  • 2022-03-12
  • 2021-07-24
相关资源
相似解决方案