菜鸡源码,专注精品下载!
当前位置:首页 > 建站教程 > 建站知识

JavaScript代码合集:禁止右键复制、F12选中和保存操作

发布时间:2024-01-05  栏目:建站知识   浏览:   分类:js教程 js代码 JS右键 js复制 JS禁止

要禁止右键复制、F12打开开发者工具和选中文本,可以使用以下JavaScript代码: ```javascript document.oncontextmenu = function() { return false; } document.onkeydown = function(e) { if (e.keyCode === 123) { return false; } } document.onselectstart = function() { return false; } ``` 这段代码首先禁止了右键点击事件,然后禁止了F12键的按下事件,最后禁止了选中文本的事件。这样就可以实现禁止右键复制、F12打开开发者工具和选中文本的功能。

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

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

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

禁用右键菜单

1、右键无任何反应

第一种方法:

document.oncontextmenu=newFunction("returnfalse;");

第二种方法:

document.oncontextmenu=function(event){if(window.event){event=window.event;}try{varthe=event.srcElement;if(!((the.tagName=="INPUT"&&the.type.toLowerCase()=="text")||the.tagName=="TEXTAREA")){returnfalse;}returntrue;}catch(e){returnfalse;}}

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

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

禁止F12审查元素

1、按F12无任何反应

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弹窗提示

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空白页

第一种方法:

functionmAlert(){varfn=function(){};fn.toString=function(){window.location='about:blank';console.log("呵呵");}console.log("%c",fn);//请不要删除这行};mAlert();

第二种方法:

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关闭当前窗口

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;}}

禁止复制

document.oncopy=function(event){if(window.event){event=window.event;}try{varthe=event.srcElement;if(!((the.tagName=="INPUT"&&the.type.toLowerCase()=="text")||the.tagName=="TEXTAREA")){returnfalse;}returntrue;}catch(e){returnfalse;}}

禁止选中

document.onselectstart=function(event){if(window.event){event=window.event;}try{varthe=event.srcElement;if(!((the.tagName=="INPUT"&&the.type.toLowerCase()=="text")||the.tagName=="TEXTAREA")){returnfalse;}returntrue;}catch(e){returnfalse;}}

禁止Ctrl+S网页另存为

document.onkeydown=function(){//禁止ctrl+sif(event.ctrlKey&&window.event.keyCode==83){returnfalse;}}
评论
建站知识
建站知识
使用技巧
调试安装
运营推广