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:

<input type="text" autocomplete="off">

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:

<input type="text" oncopy="return false;" onpaste="return false;" oncut="return false;">

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

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.

ABOUT ME

View Ehud Ashkenazi's profile on LinkedIn

Ehud Ashkenazi is a Software Developer and Webmaster at a large eLearning company.

Working with various technologies including C-Sharp(C#), ASP 3.0, ASP.NET, PHP, T-SQL, HTML and more.

Currently holding a BA in Computer Science from the Efi Arazi School of Computer Science, IDC Herzliya, Israel.