This question already has an answer here:
- Disabling Chrome Autofill 69 answers
How can we disable Chrome's autofill feature on certain <input>
s to prevent them from being automatically populated when the page loads?
At the same time I need to keep autocomplete enabled, so the user can still see the list of suggestions by clicking on the input or typing in it. Can this be done?
EDIT: Feel free to use plain Javascript or jQuery if you feel it is necessary or you feel like it would make your solution simpler.
Autofill works with name attribute of the input, so if you set a name for an input like "firstname", chrome will fill it.
If you want to disable it, use an odd name like "supermanname".
Javascript can't solve your problem.
Second solution: You can make your inputs hidden with the same names, and set their values with other inputs. I simplified the Js with jQUery.
Not a beautiful solution, but worked on Chrome 56:
Note a space on the value. And then:
I stumbled upon the weird chrome autofill behaviour today. It happened to enable on fields called: "embed" and "postpassword" (filling there login and password) with no apparent reason. Those fields had already autocomplete set to off.
None of the described methods seemed to work. None of the methods from the another answer worked as well. I came upon my own idea basing on Steele's answer (it might have actually worked, but I require the fixed post data format in my application):
Before the real password, add those two dummy fields:
Only this one finally disabled autofill altogether for my form.
It's a shame, that disabling such a basic behavior is that hard and hacky.
One solution would be to auto-fill the inputs with whitespace characters, and have them clear on focus.
Example: http://nfdb.net/autofill.php
This should stop the browser from auto-filling the fields, but still allow them to auto-complete.
Here's another example that clears the form inputs after the page loads. The advantage of this method is that the inputs never have any whitespace characters in them, the disadvantage is that there's a small possibility that the auto-filled values may be visible for a few milliseconds.
http://nfdb.net/autofill2.php
I'm not able to get my Chrome to autofill automatically on page load to test this, but you can try adding
autocomplete="off"
to your fields, then removing the attribute on load:This far I've found this one is working, having to set a Timeout of 1ms for the action to complete after chrome's auto-filling ..
I'm wondering if there's any way of attaching this function to chrome self-completion firing, or even, redeclaring it