jQuery - disable context menu right click, cut, copy and paste

jQuery - disable context menu right click, cut, copy and paste

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 example

You can disable right click functionality for whole page too using context menu.

HTML File
  1. <html lang="en">
  2. <head>
  3. <title>jQuery - disable context menu for element example </title>
  4. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
  5. </head>
  6. <body>
  7. <div class="container">
  8. <table border="1">
  9. <tr>
  10. <th>Name</th>
  11. <th>Details</th>
  12. </tr>
  13. <tr class="disableEvent">
  14. <td>ExpertPHP</td>
  15. <td>Provide Online Tutorial</td>
  16. </tr>
  17. <tr class="disableEvent">
  18. <td>Demo</td>
  19. <td>Provide Demo</td>
  20. </tr>
  21. </table>
  22. </div>
  23. </body>
  24. </html>

Script to Disable Mouse Right Click

  1. <script type="text/javascript">
  2. $(document).ready(function() {
  3. $(".disableEvent").on("contextmenu",function(){
  4. alert('right click disabled');
  5. return false;
  6. });
  7. });
  8. </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.

  1. <script type="text/javascript">
  2. $(document).ready(function() {
  3. $('.disableEvent').bind('cut copy paste', function (e) {
  4. e.preventDefault();
  5. });
  6. });
  7. </script>

Phone: (+91) 8800417876
Noida, 201301