Disable cut, copy and paste in textbox using jquery, javascript
When we don't want to display any message on cut, copy & paste
<asp:TextBox ID="TextBox1" runat="server" oncopy="return false" onpaste="return false" oncut="return false"></asp:TextBox>
When we want to display an alert message on copy, paste and cut
<script language="javascript" type="text/javascript">
function DisableCopyPaste (e)
{
// Message to display
var message = "Cntrl key/ 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 DisableCopyPaste(event)"onMouseDown="return DisableCopyPaste (event)"></asp:TextBox>
Disable cut, copy & paste using JQuery
<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>
When we don't want to display any message on cut, copy & paste
<asp:TextBox ID="TextBox1" runat="server" oncopy="return false" onpaste="return false" oncut="return false"></asp:TextBox>
When we want to display an alert message on copy, paste and cut
<script language="javascript" type="text/javascript">
function DisableCopyPaste (e)
{
// Message to display
var message = "Cntrl key/ 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 DisableCopyPaste(event)"onMouseDown="return DisableCopyPaste (event)"></asp:TextBox>
Disable cut, copy & paste using JQuery
<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>
0 comments:
Post a Comment