Tuesday, March 6, 2012

Disable copy paste in an input field

Needed to disable copy, paste in an input field and tried different javascript solutions. It worked on most of the browsers except some versions of IE. After spending sometime with custom java script I gave up and rather tried the following tags in markup which worked in all modern browsers:

<input id="myInput" onCopy="return false" onDrag="return false" onDrop="return false" onPaste="return false" autocomplete=off type="text"/>

More information on these events can be found http://developer.practicalecommerce.com/articles/1906-JavaScript-s-Copy-and-Paste-Events.

No comments: