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

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


当前回答

我有一个非常简单的解决方案,这个问题不需要代码和一个可接受的解决方案。Chrome经常读取输入的标签并自动完成。您可以简单地在标签中插入一个“空”字符。

E.g. <label>Surname</labe>

Becomes: <label>Sur&#8205;name</label>

‍是“空字符串”的HTML转义字符。

这仍然会显示“姓氏”,但自动完成不会检测字段,并尝试自动完成它。

其他回答

2021答: 可悲的是,唯一有效的东西都是令人作呕的俗气。我的解决方案是在生成前端标记时,在name属性的末尾添加一个动态生成的随机数(例如<input name="postcode-22643"…)这对浏览器来说是一种欺骗。

然后需要在服务器端添加一些东西来清理传入的post请求。例如,在NodeJS / Express中,我放入了一个中间件,并使用了一些正则表达式来从收到的post请求中删除数字段。我的是这样的,但我想在其他语言中也会有类似的东西:

const cleanseAutosuggest = function (req, res, next) {
   for (const key in req.body) {
      if (key.match(/-\d+/)) {
         req.body[key.replace(/-\d+/, "")] = req.body[key];
         delete req.body[key];
      }
   }
   next();
};

app.post("/submit", cleanseAutosuggest, function (req, res, next) {
...
})

我发布这个答案是为了给这个问题带来一个更新的解决方案。 我目前使用的是Chrome 49,没有给出的答案。 我也在寻找一个解决方案与其他浏览器和以前的版本。

把这些代码放在表单的开头

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

然后,对于您的真实密码字段,使用

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

如果这不再工作,或如果您遇到其他浏览器或版本的问题,请注释此答案。

批准:

Chrome浏览器:49 Firefox: 44,45 边缘:25 Internet Explorer: 11

我发现这个解决方案是最合适的:

function clearChromeAutocomplete()
{
// not possible, let's try: 
if (navigator.userAgent.toLowerCase().indexOf('chrome') >= 0) 
{
document.getElementById('adminForm').setAttribute('autocomplete', 'off'); 
setTimeout(function () {
        document.getElementById('adminForm').setAttribute('autocomplete', 'on'); 
}, 1500);
}
}

它必须在dom就绪后加载,或者在表单呈现后加载。

以下是我在Chrome版本51.0.2704.106上的工作方式。<input id="user_name" type="text" name="user_name" autocomplete="off" required /> And in combination with <input id="user_password" type="password" name="user_password" autocomplete="new-password" required />。我的问题是,在实现new-password之后,它仍然会在user_name字段上显示用户名的下拉列表。

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管理网站的密码,这是一个标准,最终可能会得到普遍支持。