JS禁止右键+复制+F12+选中+保存的操作代码合集

随心笔谈11个月前发布 admin
95 0

辛辛苦苦写的代码,总不想被人家轻易的剽取去,我整理了防止剽取的方法合集,免得以后总是一个个的找。

代码包含禁止右键、禁止复制、禁止F12审核元素、禁止保存首页、禁止选中的操作代码合集。

都是JS方法,虽然不可100%限制,但是也给白嫖者增加了不少难题。建议代码测试好后,在给JS加个密,让白嫖者望而却步。

禁用右键菜单

1、右键无任何反应

第一种方法:

1
document.oncontextmenu = new Function("return false;");

第二种方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
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;
}
}

第三种方法,弹窗提示并变成空白页

1
2
3
4
5
6
7
8
document.onmousedown = function mdClick(event) {
var e = event || window.event || arguments.callee.caller.arguments[0];
if (e.button == 2 || e.button == 3) {
alert("呵呵");
//不建议用以下方法,易错率大
window.location = 'about: blank';
}
}

禁止F12审查元素

1、按F12无任何反应

1
2
3
4
5
6
7
8
9
10
11
12
13
document.onkeydown = function(){
if(window.event && window.event.keyCode == 123) {    
event.keyCode=0;
event.returnValue=false;
}
if(window.event && window.event.keyCode == 13) {
window.event.keyCode = 505;
}
if(window.event && window.event.keyCode == 8) {
alert(str+"\n请使用Del键进行字符的删除操作!");
window.event.returnValue=false;
}
}

2、按F12弹窗提示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
document.onkeydown = function(){
if(window.event && window.event.keyCode == 123) {
alert("F12被禁用");
event.keyCode=0;
event.returnValue=false;
}
if(window.event && window.event.keyCode == 13) {
window.event.keyCode = 505;
}
if(window.event && window.event.keyCode == 8) {
alert(str+"\n请使用Del键进行字符的删除操作!");
window.event.returnValue=false;
}
}

3、按F12空白页

第一种方法:

1
2
3
4
5
6
7
8
function mAlert() {
var fn = function () {};
fn.toString = function () {
window.location = 'about: blank';
console.log("呵呵");
}
console.log("%c", fn);//请不要删除这行
};mAlert();

第二种方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
document.onkeydown = function(){
if(window.event && window.event.keyCode == 123) {
window.location="about:blank"//将当前窗口跳转置空白页
event.keyCode=0;
event.returnValue=false;
}
if(window.event && window.event.keyCode == 13) {
window.event.keyCode = 505;
}
if(window.event && window.event.keyCode == 8) {
alert(str+"\n请使用Del键进行字符的删除操作!");
window.event.returnValue=false;
}
}

4、按F12关闭当前窗口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
document.onkeydown = function(){
if(window.event && window.event.keyCode == 123) {
window.close(); //关闭当前窗口(防抽)
event.keyCode=0;
event.returnValue=false;
}
if(window.event && window.event.keyCode == 13) {
window.event.keyCode = 505;
}
if(window.event && window.event.keyCode == 8) {
alert(str+"\n请使用Del键进行字符的删除操作!");
window.event.returnValue=false;
}
}

禁止复制

1
2
3
4
5
6
7
8
9
10
11
12
13
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;
}
}

禁止选中

1
2
3
4
5
6
7
8
9
10
11
12
13
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;
}
}

禁止Ctrl+S网页另存为

1
2
3
4
5
6
document.onkeydown = function(){
//禁止ctrl+s
if (event.ctrlKey && window.event.keyCode==83){
return false;
}
}
© 版权声明

相关文章