我创建了一个使用标签框下拉的web应用程序。除了Chrome浏览器(Version 21.0.1180.89),这在所有浏览器中都很有效。

尽管输入字段和表单字段都有autocomplete="off"属性,Chrome坚持显示该字段以前条目的下拉历史,这是删除标签框列表。


当前回答

隐藏的输入元素技巧似乎仍然有效(Chrome 43),以防止自动填充,但要记住的一件事是Chrome将尝试基于占位符标记自动填充。您需要将隐藏输入元素的占位符与您试图禁用的输入的占位符匹配。

在我的情况下,我有一个字段的占位符文本“城市或Zip”,我正在使用谷歌地方自动完成。它似乎试图自动填写,就好像它是一个地址表单的一部分。直到我在隐藏元素上放置了与实际输入相同的占位符,这个技巧才起作用:

<input style="display:none;" type="text" placeholder="City or Zip" />
<input autocomplete="off" type="text" placeholder="City or Zip" />

其他回答

Chrome版本34现在忽略autocomplete=off, 看到这个。

很多关于这是好事还是坏事的讨论?你的观点是什么?

2021更新:将<input type="text">更改为<input type="search" autocomplete="off" >

仅此而已。保留下面的答案作为怀旧。


为了一个可靠的解决方案,你可以添加以下代码到你的布局页面:

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

Chrome尊重autocomplete=off只有当至少有一个其他输入元素的形式与任何其他自动完成值。

这对密码字段不起作用——这些在Chrome中的处理方式非常不同。详情见https://code.google.com/p/chromium/issues/detail?id=468153。

更新:Chromium团队于2016年3月11日关闭了“无法修复”的Bug。请参阅我最初提交的错误报告中的最后一条评论,以获得完整的解释。TL;DR:使用语义自动补全属性,如autocomplete="new-street-address",以避免Chrome执行自动填充。

我刚刚尝试了下面的方法,它似乎在Chrome 53上起了作用——当输入密码字段时,它还禁用了“使用密码用于:”下拉菜单。

简单地设置你的密码输入类型为文本,然后添加onfocus处理程序(内联或通过jQuery/vanilla JS)来设置类型为密码:

onfocus="this.setAttribute('type','password')"

或者更好:

onfocus="if(this.getAttribute('type')==='text') this.setAttribute('type','password')"

将输入类型属性更改为type="search"。

谷歌不会对输入的搜索类型应用自动填充。

TL;DR:告诉Chrome这是一个新的密码输入,它不会提供旧的密码作为自动补全建议:

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

由于设计决定,Autocomplete ="off"不起作用——大量研究表明,如果用户可以将密码存储在浏览器或密码管理器中,他们就会有更长时间和更难破解密码。

自动完成的规范已经改变,现在支持各种值,使登录表单更容易自动完成:

<!-- 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" />

如果你不提供这些Chrome浏览器仍然试图猜测,当它做它忽略autocomplete="off"。

解决方案是密码重置表单也存在自动完成值:

<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>

你可以使用autocomplete="new-password"标志告诉Chrome浏览器不要猜测密码,即使它已经为这个网站存储了一个。

Chrome还可以直接使用凭据API管理网站的密码,这是一个标准,最终可能会得到普遍支持。