分享学习记录
互联网技术知识

禁止鼠标右键查看网页源代码的教程

如何禁止鼠标右键查看网页源代码?建站过程中,想要保护站点某个页面代码,通常需要屏蔽右键和F12按键,有些网站程序自带禁止右键功能,还有一些程序可以通过安装插件来实现,那么,对于一些没有此功能的源码,我们应该怎么实现禁止鼠标右键查看源代码和禁按F12键查看源代码呢?其实也很简单,只需一段代码也可以实现。下面是完整代码,复制到想要禁止的页面保存即可。

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

<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>
赞(0)
文章名称:《禁止鼠标右键查看网页源代码的教程》
文章链接:https://www.bailuze.com/7503.html
本站所有文章,如无特殊说明或标注,均为本站原创发布。任何在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
本站专注于百度、搜狗、360、谷歌、bing等常见搜索引擎的优化,关键词排名的提高,诚意咨询邮箱526009505@qq.com
分享到