You are hereDisable browser autocomplete; Deny Copy and Paste
Disable browser autocomplete; Deny Copy and Paste
Many web forms include some fields that should force users to input their data manually in contrast of using built-in operation systems' (OS) features like "Copy and Paste" or the browsers' "autocomplete" feature.
Examples of such fields are: Email Verification fields, Password fields, Captcha fields and more.
So how do we disable the browsers' autocomplete feature just for a specific field and not entirely? And how can we deny visitors from using the OSs' built-in Copy and Paste feature?
Some may suggest using Javascript to capture the users' actions, like right-clicking the mouse or the Ctrl+C / Ctrl+V key combinations and then stopping the operation. But this is obviously not the best or simplest solution.
The solution is integrated in the input field properties itself together with some event capturing using Javascript.
In order to disabled the browsers' autocomplete, simply add the attribute to the input field. It should look something like this:
And if you want to deny Copy and Paste for that field, simply add the Javascript event capturing calls oncopy, onpaste, and oncut and make them return false, like so:
Easy, huh?
Some may take the next step and try using onselectstart to deny the input field's content selection from the user, but be warned: this only works for Internet Explorer. The rest of the above work great on all the major browsers: Internet Explorer, Mozilla Firefox, Apple Safari (on Windows OS, at least) and Google Chrome.
Post new comment