How do you disable autocomplete
in the major browsers for a specific input
(or form field
)?
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
- implementing html5 drag and drop photos with knock
-
Why does the box-shadow property not apply to a
In addition to
autocomplete=off
, you could also have your form fields names be randomized by the code that generates the page, perhaps by adding some session-specific string to the end of the names.When the form is submitted, you can strip that part off before processing them on the server side. This would prevent the web browser from finding context for your field and also might help prevent XSRF attacks because an attacker wouldn't be able to guess the field names for a form submission.
Sometimes even autocomplete=off would not prevent to fill in credentials into wrong fields, but not user or nickname field.
This workaround is in addition to apinstein's post about browser behavior.
fix browser autofill in read-only and set writable on focus (click and tab)
Update: Mobile Safari sets cursor in the field, but does not show virtual keyboard. New Fix works like before but handles virtual keyboard:
Live Demo https://jsfiddle.net/danielsuess/n0scguv6/
// UpdateEnd
Because Browser auto fills credentials to wrong text field!?
I notice this strange behavior on Chrome and Safari, when there are password fields in the same form. I guess, the browser looks for a password field to insert your saved credentials. Then it auto fills (just guessing due to observation) the nearest textlike-input field, that appears prior the password field in DOM. As the browser is the last instance and you can not control it,
This readonly-fix above worked for me.
Three options: First:
Second:
Third (javascript code):
This will work in Internet Explorer and Mozilla FireFox, the downside is that it is not XHTML standard.
I'd have to beg to differ with those answers that say to avoid disabling auto-complete.
The first thing to bring up is that auto-complete not being explicitly disabled on login form fields is a PCI-DSS fail. In addition, if a users' local machine is compromised then any autocomplete data can be trivially obtained by an attacker due to it being stored in the clear.
There is certainly an argument for usability, however there's a very fine balance when it comes to which form fields should have autocomplete disabled and which should not.
I think
autocomplete=off
is supported in HTML 5.Ask yourself why you want to do this though - it may make sense in some situations but don't do it just for the sake of doing it.
It's less convenient for users and not even a security issue in OS X (mentioned by Soren below). If you're worried about people having their passwords stolen remotely - a keystroke logger could still do it even though your app uses
autcomplete=off
.As a user who chooses to have a browser remember (most of) my information, I'd find it annoying if your site didn't remember mine.