ChatGPT解决这个技术问题 Extra ChatGPT

Chrome ignores autocomplete="off"

I've created a web application which uses a tagbox drop down. This works great in all browsers except Chrome browser (Version 21.0.1180.89).

Despite both the input fields AND the form field having the autocomplete="off" attribute, Chrome insists on showing a drop down history of previous entries for the field, which is obliterating the tagbox list.

Technically this question was asked about 5 months before the one referenced as "This question already has an answer here". That one is the duplicate as it came after this one.
Honestly, what if this is the reasoning for disabling autocomplete=off. What if, the plan is to make sure the web is detailed and described so that the browser you are using right now may autocomplete whatever field their latest version might want to. If that was the case, we need to describe all fields - and the browser will gracefully disable autocomplete for all fields that are outside the scope of the autocomplete script / app... Im betting on this being the case,
7 years and still we can't disable autocomplete properly... such a shame..
see bugs.chromium.org/p/chromium/issues/detail?id=370363#c7 link that recommend use autocomplete="new-password"

A
Alexander Abakumov

Prevent autocomplete of username (or email) and password:

<input type="email" name="email"><!-- Can be type="text" -->
<input type="password" name="password" autocomplete="new-password">

Prevent autocomplete a field (might not work):

<input type="text" name="field" autocomplete="nope">

Explanation:

autocomplete still works on an <input>despite having autocomplete="off", but you can change off to a random string, like nope.

Others "solutions" for disabling the autocomplete of a field (it's not the right way to do it, but it works):

1.

HTML:

<input type="password" id="some_id" autocomplete="new-password">

JS (onload):

(function() {
    var some_id = document.getElementById('some_id');
    some_id.type = 'text';
    some_id.removeAttribute('autocomplete');
})();

or using jQuery:

$(document).ready(function() {
    var some_id = $('#some_id');
    some_id.prop('type', 'text');
    some_id.removeAttr('autocomplete');
});

2.

HTML:

<form id="form"></form>

JS (onload):

(function() {
    var input = document.createElement('INPUT');
    input.type = 'text';
    document.getElementById('form').appendChild(input);
})();

or using jQuery:

$(document).ready(function() {
    $('<input>', {
        type: 'text'
    }).appendTo($('#form'));
});

To add more than one field using jQuery:

function addField(label) { var div = $('

'); var input = $('', { type: 'text' }); if(label) { var label = $('
D
Diogo Cid

UPDATE

It seems now Chrome ignores the style="display: none;" or style="visibility: hidden; attributes.

You can change it to something like:

<input style="opacity: 0;position: absolute;">
<input type="password" style="opacity: 0;position: absolute;">

In my experience, Chrome only autocompletes the first <input type="password"> and the previous <input>. So I've added:

<input style="display:none">
<input type="password" style="display:none">

To the top of the <form> and the case was resolved.


this not work anymore chrome 40 not work this solution
Not only is this ugly, but I still can't find any explanation to the Why question??
It seems Chrome now ignores them if display: none is used, so I moved the fields out of the view with absolute positioning...
display: none; will disappear the element, nothing about the autocomplete.
@AugustinRiedinger Why? Because Chrome abusively forces developer to do this because they don't respect the spec and don't want anybody to disable their terrible autofill that never gets the fields right :sigh:
i
ice cream

It appears that Chrome now ignores autocomplete="off" unless it is on the <form autocomplete="off"> tag.


For React use 'autoComplete=off.'
For an explanation of why Chrome made this change, see this answer: stackoverflow.com/a/39689037/1766230 -- They prioritize users over developers.
If you would like to provide the Chrome team with valid reasons for using autocomplete="off" please do so here: bugs.chromium.org/p/chromium/issues/detail?id=587466
Just a clarification on the above as there are conflicting reports. On the form tag add autocomplete="off" and on the individual input tags add autocomplete="new-password". Working as of Chrome 75
As Chrome 81, it now ignores autocomplete="new-password" on individual fields
c
cssyphus

2021 UPDATE: Change to

That is all. Keeping the below answer around for nostalgia.

For a reliable workaround, you can add this code to your layout page:

<div style="display: none;">
 <input type="text" id="PreventChromeAutocomplete" 
  name="PreventChromeAutocomplete" autocomplete="address-level4" />
</div>

Chrome respects autocomplete=off only when there is at least one other input element in the form with any other autocomplete value.

This will not work with password fields--those are handled very differently in Chrome. See https://code.google.com/p/chromium/issues/detail?id=468153 for more details.

UPDATE: Bug closed as "Won't Fix" by Chromium Team March 11, 2016. See last comment in my originally filed bug report, for full explanation. TL;DR: use semantic autocomplete attributes such as autocomplete="new-street-address" to avoid Chrome performing autofill.


@Jonathan Cowley-Thom: try these test pages I put up containing my workaround. On hub.securevideo.com/Support/AutocompleteOn, you should see Chrome autocomplete suggestions. Then, try the same entries on hub.securevideo.com/Support/AutocompleteOff. You should not see Chrome autocomplete suggestions. I just tested this on Chrome 45.0.2454.101m and 46.0.2490.71m, and it worked as expected on both.
One more update on this matter: I just received a notification from the Chrome team that this has been fixed. So, hopefully this workaround will very soon no longer be needed!
See my post above: "This will not work with password fields--those are handled very differently in Chrome. See code.google.com/p/chromium/issues/detail?id=468153 for more details."
@J.T.Taylor One must also have the autocomplete="off" attribute or the type="search" won't do the trick. Thanks! for finding the trick.
Changing the input type to search is NOT useful in cases like type="tel".
F
Fizzix

Modern Approach

Simply make your input readonly, and on focus, remove it. This is a very simple approach and browsers will not populate readonly inputs. Therefore, this method is accepted and will never be overwritten by future browser updates.

<input type="text" onfocus="this.removeAttribute('readonly');" readonly />

The next part is optional. Style your input accordingly so that it does not look like a readonly input.

input[readonly] {
     cursor: text;
     background-color: #fff;
}

WORKING EXAMPLE


@Basit - And that's why I called it a modern approach. Less than 1% of users in the world have Javascript turned off. So honestly, it's not worth anyones time accommodating for such a small audience when a large majority of websites rely on Javascript. Been developing websites for a very long time now, and 100% of my sites use Javascript and rely on it heavily. If users have Javascript turned off, that's their own problem and choice, not mine. They'll be unable to visit or use at least 90% of websites online with it turned off... Your downvote is completely irrelevant.
This does not work today in 49. Chrome "developers" is watching stackoverflow solutions and removing them.
This answer from September 2015 is basically a copy from the answer in November 2014 down below.
This breaks HTML form checks for mandatory. E.g. a password field using this code cannot be forced to be filled before submitting.
Remember that relying on JS on key interactions does not only break the feature for users who deactivated the JS: it also breaks it for those with slow connection (JS is not loaded yet).
C
Community

Well, a little late to the party, but it seems that there is a bit of misunderstanding about how autocomplete should and shouldn't work. According to the HTML specifications, the user agent (in this case Chrome) can override autocomplete:

https://www.w3.org/TR/html5/forms.html#autofilling-form-controls:-the-autocomplete-attribute

A user agent may allow the user to override an element's autofill field name, e.g. to change it from "off" to "on" to allow values to be remembered and prefilled despite the page author's objections, or to always "off", never remembering values. However, user agents should not allow users to trivially override the autofill field name from "off" to "on" or other values, as there are significant security implications for the user if all values are always remembered, regardless of the site's preferences.

So in the case of Chrome, the developers have essentially said "we will leave this to the user to decide in their preferences whether they want autocomplete to work or not. If you don't want it, don't enable it in your browser".

However, it appears that this is a little over-zealous on their part for my liking, but it is the way it is. The specification also discusses the potential security implications of such a move:

The "off" keyword indicates either that the control's input data is particularly sensitive (for example the activation code for a nuclear weapon); or that it is a value that will never be reused (for example a one-time-key for a bank login) and the user will therefore have to explicitly enter the data each time, instead of being able to rely on the UA to prefill the value for him; or that the document provides its own autocomplete mechanism and does not want the user agent to provide autocompletion values.

So after experiencing the same frustration as everyone else, I found a solution that works for me. It is similar in vein to the autocomplete="false" answers.

A Mozilla article speaks to exactly this problem:

https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion

In some case, the browser will keep suggesting autocompletion values even if the autocomplete attribute is set to off. This unexpected behavior can be quite puzzling for developers. The trick to really force the no-completion is to assign a random string to the attribute

So the following code should work:

autocomplete="nope"

And so should each of the following:

autocomplete="false"
autocomplete="foo"
autocomplete="bar"

The issue I see is that the browser agent might be smart enough to learn the autocomplete attribute and apply it next time it sees the form. If it does do this, the only way I can see to still get around the problem would be to dynamically change the autocomplete attribute value when the page is generated.

One point worth mentioning is that many browser will ignore autocomplete settings for login fields (username and password). As the Mozilla article states:

For this reason, many modern browsers do not support autocomplete="off" for login fields. If a site sets autocomplete="off" for a form, and the form includes username and password input fields, then the browser will still offer to remember this login, and if the user agrees, the browser will autofill those fields the next time the user visits this page. If a site sets autocomplete="off" for username and password input fields, then the browser will still offer to remember this login, and if the user agrees, the browser will autofill those fields the next time the user visits this page. This is the behavior in Firefox (since version 38), Google Chrome (since 34), and Internet Explorer (since version 11).

Finally a little info on whether the attribute belongs on the form element or the input element. The spec again has the answer:

If the autocomplete attribute is omitted, the default value corresponding to the state of the element's form owner's autocomplete attribute is used instead (either "on" or "off"). If there is no form owner, then the value "on" is used.

So. Putting it on the form should apply to all input fields. Putting it on an individual element should apply to just that element (even if there isn't one on the form). If autocomplete isn't set at all, it defaults to on.

Summary

To disable autocomplete on the whole form:

<form autocomplete="off" ...>

Or if you dynamically need to do it:

<form autocomplete="random-string" ...>

To disable autocomplete on an individual element (regardless of the form setting being present or not)

<input autocomplete="off" ...>

Or if you dynamically need to do it:

<input autocomplete="random-string" ...>

And remember that certain user agents can override even your hardest fought attempts to disable autocomplete.


@user2060451 - what doesn't work? I just tested it in 76.0.3809.87 on Windows and Mac. - both perform as per the spec. as described above. If you could provide a little more description than "does not work" I may be able to help you out.
I just tried to give (from console after everything loaded and in set it on server side) a random string for autocomplete of input element, it did not work. Giving autocomplete="off" to form element also did not work.
It works with random string. From what I noticed, it seems that no matter what attribute value you put, chrome will save it. So if you put "off", chrome will think that "off" is equal to the value you entered. The next time you have a form with "off", chrome will reuse that last value. Using a random value fix that problem, because if the value is new and unique each time, chrome will have never seen it and won't suggest anything.
Does not work any better than setting new-password
@pishpish - The OP's question didn't mention anything about password fields and was directed at a select tag which implies that it was not a password field they were having problems with (although it could have been a problem field too). Moreover, new-password is a hint in the spec, and browsers may or may not follow it for password fields only. So don't be surprised if new-password doesn't always work for password fields in every case.
K
Keith

TL;DR: Tell Chrome that this is a new password input and it won't provide old ones as autocomplete suggestions:

<input type="password" name="password" autocomplete="new-password">

autocomplete="off" doesn't work due to a design decision - lots of research shows that users have much longer and harder to hack passwords if they can store them in a browser or password manager.

The specification for autocomplete has changed, and now supports various values to make login forms easy to auto complete:

<!-- Auto fills with the username for the site, even though it's email format -->
<input type="email" name="email" autocomplete="username">

<!-- current-password will populate for the matched username input  -->
<input type="password" autocomplete="current-password" />

If you don't provide these Chrome still tries to guess, and when it does it ignores autocomplete="off".

The solution is that autocomplete values also exist for password reset forms:

<label>Enter your old password:
    <input type="password" autocomplete="current-password" name="pass-old" />
</label>
<label>Enter your new password:
    <input type="password" autocomplete="new-password" name="pass-new" />
</label>
<label>Please repeat it to be sure:
    <input type="password" autocomplete="new-password" name="pass-repeat" />
</label>

You can use this autocomplete="new-password" flag to tell Chrome not to guess the password, even if it has one stored for this site.

Chrome can also manage passwords for sites directly using the credentials API, which is a standard and will probably have universal support eventually.


Not a really compelling reason. The fact that the user wants something doesn't mean it is a smart idea. That's almost as bad as saying you will allow single character passwords in your application because the user finds it more convenient. At times, security trumps convenience...
I have a field called "ContactNoAlt" that Chrome insists on filling with an EmailAddress. Autocomplete on/off is preferred but a work-around is needed on a practical level because Chrome is falible. More pointedly autocomplete="off" is a standard - so what makes the developers of Chrome so good that they just feel they can ignore standards - perhaps one day Chrome will decide some other piece of HTML is inconvenient .... (this is starting to feel like IE5/6 de-ja-vu)
I'm a chrome user, and I don't want this behaviour. It didn't even ask me before it autofilled the password box that was popping up to make sure only I could access the web application concerned. Saving some passwords shouldn't mean autocompleting all passwords.
This answer (and Googles behaviour) ignore the fact that one of the major reasons you might want to do this is to implement your own (e.g, list from database) autocompletion behaviours.
you are trying to defend a clearly bad decision made by chrome. I am implementing the company's policy which I cannot change. So now I have to insert hacks for chrome. They currently work. If they will stop working then our company will change the default browser for employees. So now we have the same behaviour but with hacks and possibly broken pages in future upgrades. And seeing all these answers here there are a lot of devs using these hacks. Well done chrome.
N
Nathan Pitman

The solution at present is to use type="search". Google doesn't apply autofill to inputs with a type of search.

See: https://twitter.com/Paul_Kinlan/status/596613148985171968

Update 04/04/2016: Looks like this is fixed! See http://codereview.chromium.org/1473733008


this is not true as v73
This was the easiest thing for me, chrome version 98.0.4758.102. Seems to tenuous whether it'll work for other versions of Chrome though.
s
step

Always working solution

I've solved the endless fight with Google Chrome with the use of random characters. When you always render autocomplete with random string, it will never remember anything.

<input name="name" type="text" autocomplete="rutjfkde">

Hope that it will help to other people.

Update 2022:

Chrome made this improvement: autocomplete="new-password" which will solve it but I am not sure, if Chrome change it again to different functionality after some time.


When every render will have uniq random string, its impossible remember. Thant`t the point.
This didn't work for me in chrome version 99.0.4844.51 on email and password fields, but this did: autocomplete="new-password" Found on developer.mozilla.org/en-US/docs/Web/Security/…
not work for me too
d
dsuess

Browser does not care about autocomplete=off auto or even fills credentials to wrong text field?

I fixed it by setting the password field to read-only and activate it, when user clicks into it or uses tab-key to this field.

fix browser autofill in: readonly and set writeble on focus (at mouse click and tabbing through fields)

 <input type="password" readonly  
     onfocus="$(this).removeAttr('readonly');"/>

Update: Mobile Safari sets cursor in the field, but does not show virtual keyboard. New Fix works like before but handles virtual keyboard:

<input id="email" readonly type="email" onfocus="if (this.hasAttribute('readonly')) {
    this.removeAttribute('readonly');
    // fix for mobile safari to show virtual keyboard
    this.blur();    this.focus();  }" />

Live Demo https://jsfiddle.net/danielsuess/n0scguv6/

// UpdateEnd

By the way, more information on my observation:

Sometimes 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 autofills username into the nearest textlike-input field , that appears prior the password field in DOM (just guessing due to observation). As the browser is the last instance and you can not control it, sometimes even autocomplete=off would not prevent to fill in credentials into wrong fields, but not user or nickname field.


rather than using onfocus, I use a setTimeout to clear the readonly, so my users don't see the input is read only and never focus it!
Only solution works for me
m
matheca

Chrome version 34 now ignores the autocomplete=off, see this.

Lots of discussion on whether this is a good thing or a bad thing? Whats your views?


sorry for the downvote ... this is not a discussion site (try quora instead), and you don't provide an answer. Thanks for the link though.
S
Steffi

You can use autocomplete="new-password"

<input type="email" name="email">
<input type="password" name="password" autocomplete="new-password">

Works in:

Chrome: 53, 54, 55

Firefox: 48, 49, 50


This can not work, because autocomplete string is fixed. Browsers will remember new-password for next time.
t
thisisashwani

[Works in 2021 for Chrome(v88, 89, 90), Firefox, Brave, Safari] The old answers already written here will work with trial and error, but most of them don't link to any official doc or what Chrome has to say on this matter.

The issue mentioned in the question is because of Chrome's autofill feature, and here is Chrome's stance on it in this bug link - https://bugs.chromium.org/p/chromium/issues/detail?id=468153#c164

To put it simply, there are two cases -

[CASE 1]: Your input type is something other than password. In this case, the solution is simple, and has three steps. Add name attribute to input name should not start with a value like email or username, otherwise Chrome still ends up showing the dropdown. For example, name="emailToDelete" shows the dropdown, but name="to-delete-email" doesn't. Same applies for autocomplete attribute. Add autocomplete attribute, and add a value which is meaningful for you, like new-field-name It will look like this, and you won't see the autofill for this input again for the rest of your life -

Add name attribute to input

name should not start with a value like email or username, otherwise Chrome still ends up showing the dropdown. For example, name="emailToDelete" shows the dropdown, but name="to-delete-email" doesn't. Same applies for autocomplete attribute.

Add autocomplete attribute, and add a value which is meaningful for you, like new-field-name

[CASE 2]: input type is password Well, in this case, irrespective of your trials, Chrome will show you the dropdown to manage passwords / use an already existing password. Firefox will also do something similar, and same will be the case with all other major browsers. [1] In this case, if you really want to stop the user from seeing the dropdown to manage passwords / see a securely generated password, you will have to play around with JS to switch input type, as mentioned in the other answers of this question.

Well, in this case, irrespective of your trials, Chrome will show you the dropdown to manage passwords / use an already existing password. Firefox will also do something similar, and same will be the case with all other major browsers. [1]

In this case, if you really want to stop the user from seeing the dropdown to manage passwords / see a securely generated password, you will have to play around with JS to switch input type, as mentioned in the other answers of this question.

[1] A detailed MDN doc on turning off autocompletion - https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion


This isn't working. I have a WordPress site with inputs for username and password. For the username input I have <input name="portal_user" type="text" maxlength="64" autocomplete="portal">. Chrome insists on autofilling the WordPress admin username and password.
Hi @Gavin, that's why I answered by taking two separate cases. Please have a look at the second case that I wrote. There is no direct way to disable the autofill for password. MDN has a good doc on this. That's the hard truth! For username, it should ideally work. Also, by autofill, I, or any browser to be precise, is talking about the dropdown that comes up with a saved list. Are you talking of autocomplete by any chance? Will be glad to help you resolve the issue :)
E
Eduardo Cuomo

Autocomplete="Off" doesn't work anymore.

Try using just a random string instead of "Off", for example Autocomplete="NoAutocomplete"

I hope it helps.


C
Chang

Seen chrome ignore the autocomplete="off", I solve it with a stupid way which is using "fake input" to cheat chrome to fill it up instead of filling the "real" one.

Example:

<input type="text" name="username" style="display:none" value="fake input" /> 
<input type="text" name="username" value="real input"/>

Chrome will fill up the "fake input", and when submit, server will take the "real input" value.


L
Loenix

I am posting this answer to bring an updated solution to this problem. I am currently using Chrome 49 and no given answer work for this one. I am also looking for a solution working with other browsers and previous versions.

Put this code on the beginning of your form

<div style="display: none;">
    <input type="text" autocomplete="new-password">
    <input type="password" autocomplete="new-password">
</div>

Then, for your real password field, use

<input type="password" name="password" autocomplete="new-password">

Comment this answer if this is no longer working or if you get an issue with another browser or version.

Approved on:

Chrome : 49

Firefox : 44, 45

Edge : 25

Internet Explorer : 11


Unfortunately, Chrome version 49.0.2623.87 and it does not work for TextBox, I still see autocomplete poping up.
S
SuperDJ

No clue why this worked in my case, but on chrome I used autocomplete="none" and Chrome stopped suggesting addresses for my text field.


confirmed with Chrome 86.0 /Nov 2020
m
minigeek

Writing a 2020+ answer in case if this helps anyone. I tried many combinations above, though there is one key that was missed in my case. Even though I had kept autocomplete="nope" a random string, it didn't work for me because I had name attribute missing!

so I kept name='password' and autocomplete = "new-password"

for username, I kept name="usrid" // DONT KEEP STRING THAT CONTAINS 'user'

and autocomplete = "new-password" // Same for it as well, so google stops suggesting password (manage password dropdown)

this worked very well for me. (I did this for Android and iOS web view that Cordova/ionic uses)

<ion-input [type]="passwordType" name="password" class="input-form-placeholder" formControlName="model_password"
        autocomplete="new-password" [clearInput]="showClearInputIconForPassword">
</ion-input>

This solution still works as of 3 Feb 2021 - tested on latest Chrome, Firefox and IE11. Random string in autocomplete doesn't work.
glad to know that :)
this works well in latest Chrome 27/11/2021 - do not use name="email" either
Y
Yevgeniy Afanasyev

autocomplete="off" is usually working, but not always. It depends on the name of the input field. Names like "address", 'email', 'name' - will be autocompleted (browsers think they help users), when fields like "code", "pin" - will not be autocompleted (if autocomplete="off" is set)

My problems was - autocomplete was messing with google address helper

I fixed it by renaming it

from

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

to

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

Tested in chrome 71.


I think this is the latest way to remove auto complete. working in 2020 May on chrome 81
B
BenHero

Some end 2020 Update. I tried all the old solutions from different sites. None of them worked! :-( Then I found this: Use

<input type="search"/> 

and the autocomplete is gone!

Success with Chrome 86, FireFox, Edge 87.


browsers will add styling to the input and make it clearable
U
Udhav Sarvaiya

to anyone looking for a solution to this, I finally figure it out.

Chrome only obey's the autocomplete="off" if the page is a HTML5 page (I was using XHTML).

I converted my page to HTML5 and the problem went away (facepalm).


can you explain how you did this?
@user1130176 It's 2021, unless you specifically set out not to use HTML5, you are using HTML5. This solution, if it ever was one, is no longer relevant.
M
Mahdi Afzal

autocomplete=off is largely ignored in modern browsers - primarily due to password managers etc.

You can try adding this autocomplete="new-password" it's not fully supported by all browsers, but it works on some


M
Matas Vaitkevicius

Change input type attribute to type="search".

Google doesn't apply auto-fill to inputs with a type of search.


I'll downvote: tested on chrome 60: this doesn't prevent autocomplete..
C
Community

Up until just this last week, the two solutions below appeared to work for Chrome, IE and Firefox. But with the release of Chrome version 48 (and still in 49), they no longer work:

The following at the top of the form:

<input style="display:none" type="text" name="fakeUsername"/>
<input style="display:none" type="password" name="fakePassword"/>

The following in the password input element: autocomplete="off"

So to quickly fix this, at first I tried to use a major hack of initially setting the password input element to disabled and then used a setTimeout in the document ready function to enable it again.

setTimeout(function(){$('#PasswordData').prop('disabled', false);}, 50);

But this seemed so crazy and I did some more searching and found @tibalts answer in Disabling Chrome Autofill. His answer is to use autocomplete="new-password" in the passwords input and this appears to work on all browsers (I have kept my fix number 1 above at this stage).

Here is the link in the Google Chrome developer discussion: https://code.google.com/p/chromium/issues/detail?id=370363#c7


@JorgeSampayo Only works on password inputs but not on text inputs.
Why would anyone want to disable autocomplete on username/password fields? Not a surprise that browser manufacturers are ignoring autocomplete more and more. Let your users use password managers. This should be encouraged not prevented for everyone’s security.
C
Community

Instead of autocomplete="off" use autocomplete="false" ;)

from: https://stackoverflow.com/a/29582380/75799


y
yivo

In Chrome 48+ use this solution:

Put fake fields before real fields:

Hide fake fields: .visually-hidden { margin: -1px; padding: 0; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip: rect(0, 0, 0, 0); position: absolute; } You did it!

Also this will work for older versions.


@yivo Looks like the only diff between urs and og answer is the !important tags, so I added them, still not working. dropbox.com/s/24yaz6ut7ygkoql/…
@MikePurcell You don't have autocomplete="off" on the form tag. Also try to put fake inputs immediately after form tag.
@Yivo: Tried your suggestions, worked fine for email field, however autofill dropdown still happens for password field. dropbox.com/s/5pm5hjtx1s7eqt3/…
D
Drzewiecki

I managed to disable autocomple exploiting this rule:

Fields that are not passwords, but should be obscured, such as credit card numbers, may also have a type="password" attribute, but should contain the relevant autocomplete attribute, such as "cc-number" or "cc-csc". https://www.chromium.org/developers/design-documents/create-amazing-password-forms

<input id="haxed" type="password" autocomplete="cc-number">

However it comes with the great responsibility :)

Don’t try to fool the browser Password managers (either built into the browser, or external) are designed to ease the user experience. Inserting fake fields, using incorrect autocomplete attributes or taking advantage of the weaknesses of the existing password managers simply leads to frustrated users.


now it shows CC suggestions instead of other form suggestions...
R
Renato Lochetti

After the chrome v. 34, setting autocomplete="off" at <form> tag doesn`t work

I made the changes to avoid this annoying behavior:

Remove the name and the id of the password input Put a class in the input (ex.: passwordInput )

(So far, Chrome wont put the saved password on the input, but the form is now broken)

Finally, to make the form work, put this code to run when the user click the submit button, or whenever you want to trigger the form submittion:

var sI = $(".passwordInput")[0];
$(sI).attr("id", "password");
$(sI).attr("name", "password");

In my case, I used to hav id="password" name="password" in the password input, so I put them back before trigger the submition.


s
spikyjt

Whilst I agree autocomplete should be a user choice, there are times when Chrome is over-zealous with it (other browsers may be too). For instance, a password field with a different name is still auto-filled with a saved password and the previous field populated with the username. This particularly sucks when the form is a user management form for a web app and you don't want autofill to populate it with your own credentials.

Chrome completely ignores autocomplete="off" now. Whilst the JS hacks may well work, I found a simple way which works at the time of writing:

Set the value of the password field to the control character 8 ("\x08" in PHP or &#8; in HTML). This stops Chrome auto-filling the field because it has a value, but no actual value is entered because this is the backspace character.

Yes this is still a hack, but it works for me. YMMV.


I think they've picked up this hack and ignored control characters in the value, so it now evaluates to empty. See the answer by @ice-cream stackoverflow.com/a/16130452/752696 for the correct, up-to-date solution.
Same use case here: Working with user management and having own credentials autofilled. However since it's my own code and I reuse the form for creating new and editing existing users simply overriding input values via JS removed the auto-complete.
There are situations where it cannot be a user choice, for example in case of password verfication. In these cases there seems to be no way to do that. The browser now always suggests to use a saved password (even with new-password) which defeats the purpose.
B
Bailey Parker

As of Chrome 42, none of the solutions/hacks in this thread (as of 2015-05-21T12:50:23+00:00) work for disabling autocomplete for an individual field or the entire form.

EDIT: I've found that you actually only need to insert one dummy email field into your form (you can hide it with display: none) before the other fields to prevent autocompleting. I presume that chrome stores some sort of form signature with each autocompleted field and including another email field corrupts this signature and prevents autocompleting.

<form action="/login" method="post">
    <input type="email" name="fake_email" style="display:none" aria-hidden="true">
    <input type="email" name="email">
    <input type="password" name="password">
    <input type="submit">
</form>

The good news is that since the "form signature" is corrupted by this, none of the fields are autocompleted, so no JS is needed to clear the fake fields before submission.

Old Answer:

The only thing I've found to be still viable is to insert two dummy fields of type email and password before the real fields. You can set them to display: none to hide them away (it isn't smart enough to ignore those fields):

<form action="/login" method="post">
    <input type="email" name="fake_email" style="display:none" aria-hidden="true">
    <input type="password" name="fake_password" style="display:none" aria-hidden="true">
    <input type="email" name="email">
    <input type="password" name="password">
    <input type="submit">
</form>

Unfortunately, the fields must be within your form (otherwise both sets of inputs are autofilled). So, for the fake fields to be truly ignored you'll need some JS to run on form submit to clear them:

form.addEventListener('submit', function() {
    form.elements['fake_email'].value = '';
    form.elements['fake_password'].value = '';
});

Notice from above that clearing the value with Javascript works to override the autocomplete. So if loosing the proper behavior with JS disabled is acceptable, you can simplify all of this with a JS autocomplete "polyfill" for Chrome:

(function(document) {

    function polyfillAutocomplete(nodes) {

        for(var i = 0, length = nodes.length; i < length; i++) {

            if(nodes[i].getAttribute('autocomplete') === 'off') {

                nodes[i].value = '';
            }
        }
    }

    setTimeout(function() {

        polyfillAutocomplete(document.getElementsByTagName('input'));
        polyfillAutocomplete(document.getElementsByTagName('textarea'));

    }, 1);

})(window.document);