JS禁止右键|禁止选中|禁止ctrl+u|禁止F12代码

远昔 代码记录 2021-11-14 3630 0

基础防复制方式:通过js 禁止鼠标右键、禁止鼠标选中文字、禁止快捷键ctrl+u、禁止F12键

var arr = [123, 17, 18];
document.oncontextmenu = new Function("event.returnValue=false;");//禁用右键
document.onselectstart = new Function("event.returnValue=false;");//禁用选中
//禁止 ctrl+u
window.onkeydown = function (e) {
    var keyCode = e.keyCode || e.which || e.charCode;
    var ctrlKey = e.ctrlKey || e.metaKey;
    console.log(keyCode + "--" + keyCode);
    if (ctrlKey && keyCode == 85) {
	console.log("禁止ctrl+u");
	e.preventDefault();
    }
    if (arr.indexOf(keyCode) > -1) {
	console.log("其他");
	e.preventDefault();
    }
}
//屏蔽F12
document.onkeydown = function () {
    if (window.event && window.event.keyCode == 123) {
	event.keyCode = 0;
	event.returnValue = false;
	return false;
    }
}


评论

发表评论:

挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
提交评论

清空信息
关闭评论