To Disable copy, paste and cut we can use jQuery bind() function.
Syntax: $(selector).bind(event,data,function,map) ;
event: this is required parameter and it specifies one or more events to attach to the element. You can add multiple events separated by space.
data: optional parameter, it specifies additional data need to pass the function.
function: It is required parameter and belong to execute function which call on event occur
map: It define an event map which contains one or more events or functions
The bind() method attaches one or more event handlers for selected elements, and specifies a function to run when the event occurs.
Disable cut, copy and paste jQuery Example:
Check below code which disable copy and paste of content inside text input field.
You can try to run the following code to disable copy paste of content using jQuery −
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<!DOCTYPE html> <html> <head> <title>jQuery to Disable Copy and Paste on Website</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script> $(document).ready(function(){ $('#demotxt').bind("cut copy paste",function(e) { e.preventDefault(); }); }); </script> </head> <body> <input type = "text" id="demotxt">Copy and paste function doesn't work on this input field. </body> </html> |