jQuery – disable context menu right click, cut, copy and paste
In this post we will give you information about jQuery – disable context menu right click, cut, copy and paste. Hear we will give you detail about jQuery – disable context menu right click, cut, copy and pasteAnd how to use it also give you demo for it if it is necessary.
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
- <htmllang="en">
- <head>
- <title>jQuery - disable context menu for element example </title>
- <scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
- </head>
- <body>
- <divclass="container">
- <tableborder="1">
- <tr>
- <th>Name</th>
- <th>Details</th>
- </tr>
- <trclass="disableEvent">
- <td>onlinecode</td>
- <td>Provide Online Tutorial</td>
- </tr>
- <trclass="disableEvent">
- <td>Demo</td>
- <td>Provide Demo</td>
- </tr>
- </table>
- </div>
- </body>
- </html>
<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 >
<table border="1">
<tr>
<th>Name</th>
<th>Details</th>
</tr>
<tr >
<td>onlinecode</td>
<td>Provide Online Tutorial</td>
</tr>
<tr >
<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');
- returnfalse;
- });
- });
- </script>
<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>
<script type="text/javascript">
$(document).ready(function() {
$('.disableEvent').bind('cut copy paste', function (e) {
e.preventDefault();
});
});
</script>
Hope this code and post will helped you for implement jQuery – disable context menu right click, cut, copy and paste. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs