一、禁止右键
//方法一
document.onmousedown = function () {
if (event.button == 2) {
return false;
}
}
//方法二
document.oncontextmenu = function () {
return false;
}
二、禁止F12
//方法一
document.onkeydown = function (e) {
var currentKey = 0, k = e || window.event;
currentKey = k.keyCode || k.which || k.charCode;
if (currentKey == 123) {
window.event.cancelBubble = true;
window.event.returnValue = false;
}
}
//方法二
document.onkeydown = function () {
if (window.event && window.event.keyCode == 123) {
window.event.returnValue = false;
}
}
三、禁止选中
body{
-webkit-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
user-select:none;
}
四、禁止复制
function noCopy(){
event.returnValue = false;
}
<body oncopy="noCopy()"></body>
五、禁止缓存
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Cache-Control" content="no-cache"/>
<meta http-equiv="Expires" content="0"/>
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步