Chrome禁用自动填充autocomplete="off"无效

通常情况下,如果不希望输入框自动填充,可以给input设置autocomplete="off"

但是当输入框type="password"时,第一次填写时Chrome会提示是否保存密码。如果保存了密码,下次打开时Chrome会自动填充密码输入框,并用保存的用户名或邮箱填充在密码输入框之前的任意输入框。

这是因为,Chrome会忽视密码输入框的autocomplete="off"。针对Chrome这个问题,可以使用以下解决办法。
测试用Chrome版本:Version 58.0.3029.110。

可能可行的方法:添加隐藏的input

在用户名和密码输入框之前,添加两个隐藏的输入框。



我尝试了这种方法,但还是自动填充......如果不隐藏是可行的,但不能不隐藏啊!这种方法可能适用旧版本的Chrome吧。

可行方法:改autocomplete的值

type="password"input中添加autocomplete="new-password"。有点莫名奇妙,但真的好用。这个方法在Chrome开发者的讨论中被提到:

Comment 7 by [email protected] ,
May 16 2014
The distinction for Autofill vs. Password Autofill is basically who does the filling, not the type of text field. For sites that use e-mail address for usernames, Autofill might want to allow you to select from known e-mail addresses (which can be disabled via autocomplete=off) while Password Autofill might want to fill with a username for this site (which can't be disabled). If both features want to put suggestions in the same field, Password Autofill wins.
In any case, ignoring autocomplete=off is intended. It's not clear from your question if you think that this also shouldn't fill because the markup is different between the two forms. We use this as one indication for filling, but not the only one. Signup forms and login forms may have slightly different markup, but if you save your password during signup we still want to fill it when you log in.
However, we are working on being smarter about when to fill, including not filling on password forms that require confirmation ( issue 352347 ). You could/should also mark these fields with autocomplete="new-password". This attribute was very recently added to the spec, but we should have support for it by M37. It would also prevent filling in this case (though we would still save the password if it was updated).

看Stackflow上有建议autocomplete="false"的,可以试试。

参考阅读:

  • Disabling Chrome Autofill: https://stackoverflow.com/questions/15738259/disabling-chrome-autofill?page=1&tab=votes#tab-top
  • autofill for forms not deactivatable:
    https://bugs.chromium.org/p/chromium/issues/detail?id=370363#c7
  • 'autocomplete="off"'在Chrome中不起作用解决方案:
    http://blog.csdn.net/xw505501936/article/details/52129579

你可能感兴趣的:(Chrome禁用自动填充autocomplete="off"无效)