I would like to prevent a user from either:
This is not working.
<html>
<head runat="server">
<title>Confirm email page</title>
<script type="text/javascript" language="javascript">
function DisableRightClick(event) {
//For mouse right click
if (event.button == 2) {
}
}
function DisableCtrlKey(e) {
var code = (document.all) ? event.keyCode : e.which;
// look for CTRL key press
if (parseInt(code) == 17) {
window.event.returnValue = false;
}
}
</script>
</head>
<body style="font-family: Verdana; font-size: 1em">
<form id="form1" runat="server">
<div>
<h1>Confirm Email</h1>
<asp:Label ID="Label2" runat="server" Text="Enter Email Address: "></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" oncopy="return false" onMouseDown="DisableRightClick(event)" ></asp:TextBox><br />
<asp:Label ID="Label3" runat="server" Text="Confirm Email Address: "></asp:Label>
<asp:TextBox ID="TextBox3" runat="server" onKeyDown="return DisableCtrlKey(event)"></asp:TextBox><br />
</div>
</form>
</body>
</html>
GOT IT WORKING!!!!
<div>
<h1>Copy Paste Preventer!!!</h1>
<asp:Label ID="Label1" runat="server" Text="Enter Username: "></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:Label ID="Label2" runat="server" Text="Enter Email Address: "></asp:Label>
<asp:TextBox ID="email" runat="server" oncopy="return false" onpaste="return false" oncut="return false" oncontextmenu="forms[0].elements[0].value++; return false"></asp:TextBox><br />
<asp:Label ID="Label3" runat="server" Text="Confirm Email Address: "></asp:Label>
<asp:TextBox ID="TextBox3" runat="server" oncopy="return false" onpaste="return false" oncut="return false" oncontextmenu="forms[0].elements[0].value++; return false"> </asp:TextBox><br />
</div>
Disable Copy and Paste in an ASP.NET Webpage TextBox without JavaScript; we need to set the following properties of the TextBox: oncopy="return false" onpaste="return false" oncut="return false"
Use KeyPress, KeyUp, KeyDown for the same... <asp:TextBox onkeypress="return false;" onkeyup="return false;" onkeydown="return false;" ... You can use javascript key events for this. Use KeyPress, KeyUp, KeyDown for the same...
You can use jquery for this: $('body'). bind('copy paste',function(e) { e. preventDefault(); return false; });
To disable the copy and paste function in PDFs, you need to prevent the ability to select text with the cursor. If a user can't select the text, then they can't right-click and copy with the mouse or use Ctrl-C as a keyboard command.
When using jQuery this is fairly simple and it is fully compatible with ASP.NET:
<script type='text/javascript' src='http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js'>
</script>
<script type="text/javascript">
$(function() {
$('input[id$=TextBox2]').bind('cut copy paste', function(e) {
e.preventDefault();
alert('You cannot ' + e.type + ' text!');
});
});
</script>
Here is an article that explains how this works together with ASP.NET:
http://www.dotnetcurry.com/ShowArticle.aspx?ID=398
As Scott pointed out: In production, you should put the jQuery reference on the bottom of your html however(still inside the body tag).
UPDATE
Since you asked to prevent the context menu entirely you can do something like this:
Add this script:
<script type="text/javascript">
document.getElementById('TextBox2').oncontextmenu = function (){
return false;
};
</script>
The menu item is not shown when false
is returned. Here is an overview of browsersupport for this:
http://help.dottoro.com/ljhwjsss.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With