Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable Paste (Ctrl+V) with jQuery?

How can I disable Paste (Ctrl+V) option using jQuery in one of my input text fields?

like image 547
Misam Avatar asked Apr 01 '11 07:04

Misam


People also ask

How do I restrict copy and paste in jQuery?

To disable cut, copy and paste of a content in jQuery, use the jQuery bind() function.

How do I turn off copy and paste in HTML?

You can use jquery for this: $('body'). bind('copy paste',function(e) { e. preventDefault(); return false; });

How do I restrict copy and paste in text field?

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) .


1 Answers

This now works for IE FF Chrome properly... I have not tested for other browsers though

$(document).ready(function(){    $('#txtInput').on("cut copy paste",function(e) {       e.preventDefault();    }); }); 

Edit: As pointed out by webeno, .bind() is deprecated hence it is recommended to use .on() instead.

like image 73
Misam Avatar answered Sep 28 '22 03:09

Misam