In some cases, you do not need to right-click the page, for example, you do not want to view the source code of the page, or copy the content of the page. Of course, users can use various methods to achieve their goals, but we can try to increase the difficulty for them to achieve this goal. Use the following js script to implement this function:
<script type="text/javascript">// <![CDATA[function doProhibit(){if(window.Event) document.captureEvents(Event.MOUSEUP);function nocontextmenu() { event.cancelBubble = true event.returnvalue = false; return false;}function norightclick(e) { if (window.Event) { if (e.which == 2 || e.which == 3) return false; } else if (event.button == 2 || event.button == 3) {event.cancelBubble = true event.returnvalue = false;return false; }}document.oncontextmenu = nocontextmenu; // for IE5+ document.onmousedown = norightclick; // }// ]]></script>
However, in some cases, the right-click of the input box cannot be blocked. You can use the following script:
if (document.layers) {document.captureEvents(Event.MOUSEDOWN);}document.onmousedown = click;document.oncontextmenu = new Function("return false;")function click(e) { e = e || event; if (e.button == 2) { var tag = e.srcElement || e.target; if (tag.type == "text" || tag.type == "textarea") { document.oncontextmenu = new Function("return true;") } else { document.oncontextmenu = new Function("return false;") } }}