37

I have a input type text for user to change their email & password in account setting page.

How can stop Chrome auto fill the input.

Chrome remember the input data from log in page and it auto fill in account setting page.

Chrome auto fill the input change my email & password in account setting page

Ben
  • 2,562
  • 8
  • 37
  • 62
  • 1
    Did you try Googling the exact question? – Itay Aug 30 '13 at 11:09
  • You need to do this programmatically or simply via chrome. – Sasidharan Aug 30 '13 at 11:10
  • I have a simple solution for you! [Disabling Chrome Autofill](http://stackoverflow.com/questions/15738259/disabling-chrome-autofill/41217143#41217143#answer-41217143) – نرم افزار حضور و غیاب Dec 19 '16 at 06:51
  • Try jQuery disableAutoFill plugin https://github.com/terrylinooo/jquery.disableAutoFill – Terry Lin Mar 29 '18 at 03:27
  • This should not be marked as "This question already has an answer here". The link refers to a solution that is referring to a password, not the general question of how to disable auto fill but how to disable it for a password box. So this is invalid. – Yusha Mar 30 '18 at 13:36
  • Simply use below code, this should help you. It will set autocomplete attribute to "new-loc" (you can add any custom value like new-address etc.). var input = $("#myaddress"); this.$window.google.maps.event.addDomListener(input[0], 'focusin', e => e.target.setAttribute('autocomplete', 'new-location')); – Rahul Jha Dec 16 '20 at 07:24

14 Answers14

60

We are no longer dependent on hacks for this. You can set autocomplete to new-password and it will work as intended.

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

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-autocomplete

Peo Bondesson
  • 797
  • 1
  • 6
  • 6
29

Are you explicitly setting the values as blank? For example:

<input type="text" name="textfield" value="">

That should stop browsers putting data in where it shouldn't. Alternatively, you can add the autocomplete attribute to the form tag:

<form autocomplete="off" ...></form>
Roy M J
  • 6,926
  • 7
  • 51
  • 78
  • 1
    Correct, if it is not set to false Chrome may displays incorrect values when editing an object and that could be annoying if the user save without checking all inputs. +1 – glautrou Aug 30 '13 at 11:14
  • 61
    It doesn't work – Jaider Jan 06 '15 at 03:41
  • 14
    It worked for a while but since the Chrome's last few updates it has stopped working now. – Oxon Jan 16 '15 at 12:30
  • 7
    It no longer works - please update your answer! – ŁukaszBachman Jul 10 '15 at 06:33
  • 3
    This will no longer work on newer versions of Chrome. Google insists on overriding every workaround there is, as they do not seem to like AutoFill getting disabled. – arimbun Feb 07 '16 at 23:36
  • 4
    This ridiculous. There are use cases for disabling auto complete on a field by field basis. Typeahead functionality is one of them. Right now due to this insane bug in Chrome it's own autofill is showing over the top of my auto-complete list generated from the typeahead library! – Matt May 06 '18 at 02:51
21

Solution 1: Putting 2 lines of code under under <form ..> tag does the trick.

<form id="form1" runat="server" >
<input style="display:none" type="text" name="fakeusernameremembered"/>
<input style="display:none" type="password" name="fakepasswordremembered"/>

...

Read more

Solution 2: It removes "name" and "id" attributes from elements and assigns them back after 1ms. Put this in document get ready.

$('form[autocomplete="off"] input, input[autocomplete="off"]').each(function () {

                var input = this;
                var name = $(input).attr('name');
                var id = $(input).attr('id');

                $(input).removeAttr('name');
                $(input).removeAttr('id');

                setTimeout(function () {
                    $(input).attr('name', name);
                    $(input).attr('id', id);
                }, 1);
            });

Solution 3: Tested in Chrome 60.0.3112.101

<input type="password" name="pwd" autocomplete="new-password">
Sangram Nandkhile
  • 17,634
  • 19
  • 82
  • 116
  • 3
    Worked for me, I really dont know why chrome doesnt follow the autocomplete attribute? – Zapnologica Oct 24 '14 at 09:33
  • 7
    it worked..."unbelievable" Google! Looks like they are trying to do what IE has done for years -- ignore standards. Simply unbelievable. – H. Ferrence Oct 29 '15 at 23:31
  • As I think more about this, it poses a huge and serious security exposure. Any site can harvest usernames and passwords, ip addresses from the client, and a host of other _SERVER variable info. I just proved it on my site by looking at the _POST vars submitted. And I thought Google was smart. Fooled me. – H. Ferrence Oct 29 '15 at 23:47
  • 1
    it works, but can somebody explain, how is this even possible? – Zeeshan Jan 29 '16 at 11:38
  • @Zeeshan: If I understand it correctly Chrome maintains only one password per page. So as HTML renders, fake password is the first password and it ignores the next password fields. – Sangram Nandkhile Jan 29 '16 at 17:19
  • 3
    Does not work in Chrome 49. – eYe Mar 31 '16 at 16:01
  • @eYe: Check if solution 2 works for you ! – Sangram Nandkhile Apr 01 '16 at 06:23
  • Brilliant! Solution 2 is the only solution working for me after trying tons of other solutions. See post [here](https://stackoverflow.com/questions/44685854) – J0ANMM Jul 05 '17 at 12:01
  • Solution #2 seems to work on Chrome 60 as well. The only downside is if user directly clicks on a password field. I tried to dynamically change the type from text to password in the on('click') event but then it would autoselect the first option from the autofill dropdown list. However, if the user enters email address before password, then no autofill activity occurred. – Mike Purcell Aug 28 '17 at 19:55
  • solution 2 doesnt work. reference error. – My1 Jan 23 '18 at 13:59
  • The only thing worked for me was adding "" this. – Raghav Mar 22 '19 at 07:31
  • Did not work dear, Thanks. – Kamlesh Feb 04 '20 at 13:58
11

This issue still exists as of Version 55.0.2883.87 m. (on Windows 10)

Solutions like setting the autocomplete attribute on a form

or adding fake input fields and removing the name attribute before submit do not work anymore, since Chrome ignores or instantly auto-completes them on removal.

The only way to get it currently to work as intended is to set the autocomplete attribute to "new-password"

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

even on non password type inputs.

DefaultError
  • 326
  • 3
  • 7
4

The latest version of Chrome (46.0.2490.86) appears to have changed behaviour again. This time, AutoFill has nothing to do with autocomplete or readonly or other workarounds suggested here (and on these bug reports https://code.google.com/p/chromium/issues/detail?id=468153, https://bugs.chromium.org/p/chromium/issues/detail?id=587466)

Rather, AutoFill now looks at the label next to the input box and generates an AutoFill based on that (as well as the id and name). A big clue is how AutoFill can actually fill multiple fields at once (e.g. Street, Suburb and State). It appears to be using several techniques (label, name, id) to discern the spatial relationship between fields.

So a workaround is to insert junk text into the label inside a hidden span...

S<span style="display:none">_</span>uburb:

...and also obfuscate/remove the id and name. This was the only thing that prevented Suburb AutoFill for me.

Richard Kennard
  • 1,325
  • 11
  • 20
3

Unfortunately autocomplete="off" didn't work for me (anymore). So here is my solution:

First read and then remove "name" and "id" attributes from elements. Then, after 1ms, set these attributes back again with values read before. For me it works :)

<form autocomplete="off"><br />
<input type="text" name="username" id="username" /><br />
<input type="password" name="password" id="password" /><br />
</form>

<pre>
    $('form[autocomplete="off"] input, input[autocomplete="off"]').each(function(){

        var input = this;
        var name = $(input).attr('name');
        var id = $(input).attr('id');

        $(input).removeAttr('name');
        $(input).removeAttr('id');      

        setTimeout(function(){ 
            $(input).attr('name', name);
            $(input).attr('id', id);            
        }, 1);
    }); 
</pre>
Gwenc37
  • 2,064
  • 7
  • 18
  • 22
etzzzz
  • 39
  • 2
  • Problem is, sometimes Chrome takes much longer than 0-1 ms to autofill these fields. Happens to me very often – mowgli Aug 20 '14 at 08:57
3

By setting autocomplete="new-password" , it works. Before testing, you clear browsing data first

Frank Kwok
  • 86
  • 1
  • 9
2

Chrome ignores both autocomplete="anything" and hidden fields. A HTML/CSS workaround would be using an absolute positioned password field before the real one:

<input type="text" name="username" required>
<input style="visibility: hidden; position: absolute; left:-99999px" type="password" name="fakepasswordfieldtoturnoffautocomplete">
<input type="password" name="password" required>

EDIT:

As referred in multiple other answers in other duplicate questions, the most elegant working solution so far is this:

 <input type="password" readonly onfocus="this.removeAttribute('readonly');"/>
juliuslaak
  • 53
  • 1
  • 6
  • 1
    Chrome does not ignore the value of an `autocomplete` property, it parses it according to https://html.spec.whatwg.org/multipage/forms.html#autofilling-form-controls:-the-autocomplete-attribute -- except that it always ignores `"off"`. – Luke Sep 25 '16 at 18:41
2

Almost jumped out the window trying to solve this... seems Google now ignores Autocomplete ON and OFF. I had used on older fix (such as fake hidden password fields - which also no longer worked). Based on the living standard spec - you need to use an auto-fill tokens instead. You must use them in the appropriate use-case context. Hope this is helpful.

https://html.spec.whatwg.org/multipage/forms.html#autofilling-form-controls:-the-autocomplete-attribute

Nappz
  • 101
  • 1
  • 5
  • Seems like with the tokens there is no way to turn off the autocomplete, just ways to make it more helpful, is that what you've seen? – Luke Sep 25 '16 at 18:52
  • I just wrote a nasty bug report because this is absolute horseshit. I cannot stand developers who think they are smarter than their users and force this nonsense on them. Clearly they have made repeated attempts to enforce autocomplete. It is not acceptable. – BarryBones41 Jan 10 '17 at 17:13
1

Try hidden password element

<form>
   <input type="text" name="fakeusername" class="fake-autofill-fields"/>
    <input type="password" name="fakepassword" class="fake-autofill-fields"/>
...
...
</form>


<script>
    $(document).ready(function () {
        $(".fake-autofill-fields").show();
        window.setTimeout(function () {

            $(".fake-autofill-fields").hide();
        }, 1);
    });
</script>
Fatih
  • 945
  • 15
  • 26
0

Enter a value of ' ' (a blank space) for the username field and Chrome doesn't autopopulate username or password.

<input type = 'text' value = ' ' name = 'username' />

If you're ever populating the username with a user-entered value, code to enter a ' ' if there's no user-entered value.

Geoff Kendall
  • 1,307
  • 12
  • 13
  • 1
    with this method, the placeholder is not shown as the browser thinks there is something entered into the field. – GobiRan Oct 23 '15 at 13:26
0

Try this:

<div id="form_container">
    <input type="text" name="username" autocomplete="off">
    <input type="password" name="pwd" autocomplete="off">
    <input tytep="submit" name="login" id="login" value="Log In">
</div>`

The jquery code:

jQuery("#login").click(function(){
    jQuery("#form_container").wrap('<form method="post"></form>');
    jQuery("form").submit();
});

If you don't wrap your input fields into a form, then the chrome's autofill won't come up.

When you click on the submit button, just frap the fields around the form and fire a submit() on the form.

Anptk
  • 1,125
  • 2
  • 17
  • 28
Ivan Bauer
  • 65
  • 8
0

I had a similar problem. After all of the attempts failed. I tried this hack of setting

type = "search"

instead of text. Even though its not a pretty hack. It does not cause any issues in majority of cases. type search is no different than text as of now.

karthik
  • 7,041
  • 1
  • 13
  • 12
-1

This works:

<form autocomplete="off" ...></form>

Tested on Chrome 56.0.2924.87 (64-bit)