Emlog一句简单的代码让网页禁止右键菜单
•建站折腾
3450 0
为了防止一些“小偷”,可以用js代码禁止右键。一句代码即可实现全网页禁止右键菜单功能
将以下代码放在网页head头部文件里面
<script src="https://cdn.jsdelivr.net/gh/iuiurun/tyup@latest/irom/js/f12stop.js" type="text/javascript"></script>
<textarea id="mytextarea"></textarea>
<script>
$(document).ready(function(){
$(document).bind("contextmenu",function(e){
return false;
});
});
</script>
结束
下面是JS文件
可以放在footer.php 以上二选一即可
<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>