![图片[1]-禁止F12与右键功能防止偷代码贼-墨吻博客](https://mowen3.oss-cn-qingdao.aliyuncs.com/wp-content/uploads/2020/03/女孩子-鯨鱼-4k高清动漫壁纸_彼岸图网.jpg)
Hi,boys.
咳,老墨吻黔驴技穷了,想不出啥文案来了,先这么写吧,这次又是源代码系列。
分为两个功能,简单来说就是禁止鼠标右键跟禁止F12审查元素。
怎么说来着,都说尊重原创,原创不易,可还总是有人随意搬砖,恶意采集。这次就来惩戒一下这种搬砖的吧。
长期关注墨吻博客的老吊们应该都知道代码怎么插入吧,还不会的话这边再说一次。
其实插在哪里都一样,不过应该养成良好的编程习惯
一般都放在<head></head>里面
这样保证在显示页面之前,所有的javascript代码已经经过解析了。
第一个是禁止右键,将下列代码插入进你的网站内,用户浏览是鼠标将无法进行右键复制操作。
<script>//禁止右键
function click(e) {
if (document.all) {
if (event.button==2||event.button==3) { alert("禁止恶意拿代码的");
oncontextmenu='return false';
}
}
if (document.layers) {
if (e.which == 3) {
oncontextmenu='return false';
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
document.oncontextmenu = new Function("return false;")
document.onkeydown =document.onkeyup = document.onkeypress=function(){
if(window.event.keyCode == 12) {
window.event.returnValue=false;
return(false);
}
}
</script>
第二个是禁止F12键,同上操作。
<script>//禁止F12
function fuckyou(){
window.close(); //关闭当前窗口(防抽)
window.location="about:blank"; //将当前窗口跳转置空白页
}
function click(e) {
if (document.all) {
if (event.button==2||event.button==3) {
alert("禁止恶意拿代码的");
oncontextmenu='return false';
}
}
if (document.layers) {
if (e.which == 3) {
oncontextmenu='return false';
}
}
}
if (document.layers) {
fuckyou();
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
document.oncontextmenu = new Function("return false;")
document.onkeydown =document.onkeyup = document.onkeypress=function(){
if(window.event.keyCode == 123) {
fuckyou();
window.event.returnValue=false;
return(false);
}
}
</script>
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END













暂无评论内容