其实右键是必须要禁的,然后就是ctrl+u查看元代码。首先如果是管理员就不起用,是游客就起用。这样方便管理员。JS代码如下
<?php if( current_user_can( 'manage_options' ) ) { ?> <script> //屏蔽F12和右键 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;") //禁止f12 document.onkeydown = document.onkeyup = document.onkeypress = function () { if (window.event.keyCode == 123) { window.event.returnValue = false; return (false); } } //按键触发 禁止ctlt+u document.onkeydown = function(){ //禁止ctrl+u if (event.ctrlKey && window.event.keyCode==85){ return false; } } </script> <?php } ?>
参考文章来源: