jQuery - disable context menu right click, cut, copy and paste
If You are looking for a simple way to disable right click for any html element then here you will find the best solution to disable right click on page.
There are some reasons why you will disable the right click of mouse button.
It may be you want to show your own menu or you want to prevent user to copy content from your page.
If you want to show your own menu on right click then follow this link :
jQuery making custom right-click context menu exampleYou can disable right click functionality for whole page too using context menu.
HTML File
- <html lang="en">
- <head>
- <title>jQuery - disable context menu for element example </title>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
- </head>
- <body>
- <div class="container">
- <table border="1">
- <tr>
- <th>Name</th>
- <th>Details</th>
- </tr>
- <tr class="disableEvent">
- <td>ExpertPHP</td>
- <td>Provide Online Tutorial</td>
- </tr>
- <tr class="disableEvent">
- <td>Demo</td>
- <td>Provide Demo</td>
- </tr>
- </table>
- </div>
- </body>
- </html>
Script to Disable Mouse Right Click
- <script type="text/javascript">
- $(document).ready(function() {
- $(".disableEvent").on("contextmenu",function(){
- alert('right click disabled');
- return false;
- });
- });
- </script>
Script to Disable Cut Copy & Paste
Using this script, you can prevent user to cut (CTRL+X), copy (CTRL+C) and paste (CTRL+V)content from your web pages.
- <script type="text/javascript">
- $(document).ready(function() {
- $('.disableEvent').bind('cut copy paste', function (e) {
- e.preventDefault();
- });
- });
- </script>