分享一下禁用鼠标右键跟F12的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 qinor(){
window.close(); //关闭当前窗口(防抽)
window.location="about:blank"; //将当前窗口跳转置空白页
}
function click(e) {
if (document.all) {
if (event.button==2||event.button==3) {
alert("欢迎来到“奇诺博客”,就算是大朋友也不许乱按F12");
oncontextmenu='return false';
}
}
if (document.layers) {
if (e.which == 3) {
oncontextmenu='return false';
}
}
}
if (document.layers) {
qinor();
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) {
qinor();
window.event.returnValue=false;
return(false);
}
}
</script>
Chin