how do i prevent the user from Copying any text in asp.net page using jQuery?
To disable cut, copy and paste of a content in jQuery, use the jQuery bind() function.
The event. preventDefault() method stops the default action of an element from happening. You can use this method toprevent a TextBox control from Cut (Ctrl+X) , Copy (Ctrl+C) and Paste (Ctrl+V) .
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"
That means CTRL + C should be disabled and CTRL + A should be enabled.
You can disable the right click and also bind keyup event on document to detect copy command key combination "Ctl + C" and returning false.
To disable right click:
jQuery(document).bind("contextmenu", function(e) {
e.preventDefault();
});
To detect Ctl + C:
jQuery(document).ready(function()
{
var ctlPressed = false; //Flag to check if pressed the CTL key
var ctl = 17; //Key code for Ctl Key
var c = 67; //Key code for "c" key
jQuery(document).keydown(function(e)
{
if (e.keyCode == ctl)
ctlPressed = true;
}).keyup(function(e)
{
if (e.keyCode == ctl)
ctlPressed = false;
});
jQuery(".your-no-copy-area").keydown(function(e)
{
if (ctlPressed && e.keyCode == c)
return false;
});
});
Watermark is your solution. I can easily disable Javascript.
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