Sunday, August 17, 2014

Disable right click, cut,copy and paste using Javascript

Disable Right Click in Two way

1. Method

<asp:TextBox ID="TextBox1" runat="server" oncopy="return false" onpaste="return false" oncut="return false"></asp:TextBox>
 <script language="javascript" type="text/javascript">
function DisableRightClick (e)
{
 // Message to display
 var message = "Right Click Option disabled";
 // check mouse right click or Ctrl key press
var kCode = event.keyCode || e.charCode;
//FF and Safari use e.charCode, while IE use e.keyCode
 if (kCode == 17 || kCode == 2)
 {
 alert(message);
 return false;
 }
}
</script>
 <asp:TextBox ID="TextBox1" runat="server" onKeyDown="return  DisableRightClick(event)"onMouseDown="return  DisableRightClick (event)"></asp:TextBox>

2. Method

 <script type="text/javascript">
$(document).ready(function() {
 $('#TextBox1').bind('copy paste cut',function(e) {
 e.preventDefault(); //disable cut,copy,paste
 alert('cut,copy & paste options are disabled !!');
 });
});
</script>
 <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>


No comments: