Chrome ignores autocomplete=“off”

2018-12-31 05:25发布

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.

30条回答
孤独总比滥情好
2楼-- · 2018-12-31 05:40

After having tried all solutions, Here is what seems to be working for chrome version:45, with form having password field :

 jQuery('document').ready(function(){
        //For disabling Chrome Autocomplete
        jQuery( ":text" ).attr('autocomplete','pre'+Math.random(0,100000000));
 });
查看更多
冷夜・残月
3楼-- · 2018-12-31 05:42

In Chrome 48+ use this solution:

  1. Put fake fields before real fields:

    <form autocomplete="off">
      <input name="fake_email"    class="visually-hidden" type="text">
      <input name="fake_password" class="visually-hidden" type="password">
    
      <input autocomplete="off" name="email"    type="text">
      <input autocomplete="off" name="password" type="password">
    </form>
    
  2. 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;
    }
    
  3. You did it!

Also this will work for older versions.

查看更多
低头抚发
4楼-- · 2018-12-31 05:42

The hidden input element trick still appears to work (Chrome 43) to prevent autofill, but one thing to keep in mind is that Chrome will attempt to autofill based on the placeholder tag. You need to match the hidden input element's placeholder to that of the input you're trying to disable.

In my case, I had a field with a placeholder text of 'City or Zip' which I was using with Google Place Autocomplete. It appeared that it was attempting to autofill as if it were part of an address form. The trick didn't work until I put the same placeholder on the hidden element as on the real input:

<input style="display:none;" type="text" placeholder="City or Zip" />
<input autocomplete="off" type="text" placeholder="City or Zip" />
查看更多
呛了眼睛熬了心
5楼-- · 2018-12-31 05:44

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

I made the changes to avoid this annoying behavior:

  1. Remove the name and the id of the password input
  2. 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.

查看更多
梦寄多情
6楼-- · 2018-12-31 05:46

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
查看更多
其实,你不懂
7楼-- · 2018-12-31 05:47

Change input type attribute to type="search".

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

查看更多
登录 后发表回答