To disable right click context menu you can use one of the following methods.
Method 1 – Using attribute oncontextmenu attribute of the body tag.
By using this you can block the right click action and the context menu without using JavaScript.
- <body oncontextmenu="return false">
This will be useless if you need to do some action on the click. In such a case use the Method 2.
Method 2 – Using JavaScript.
Place the following JavaScript and modify the script as you need. This will just show a popup window to the user saying that Right clicking is disabled.
- <script language="javascript">
- document.onmousedown = disableRightClick;
- function disableRightClick(e) {
- if (event.button == 2) {
- alert("Right click is disabled.");
- return false;
- }
- }
- </script>
No comments:
Post a Comment