我创建了一个使用标签框下拉的web应用程序。除了Chrome浏览器(Version 21.0.1180.89),这在所有浏览器中都很有效。
尽管输入字段和表单字段都有autocomplete="off"属性,Chrome坚持显示该字段以前条目的下拉历史,这是删除标签框列表。
我创建了一个使用标签框下拉的web应用程序。除了Chrome浏览器(Version 21.0.1180.89),这在所有浏览器中都很有效。
尽管输入字段和表单字段都有autocomplete="off"属性,Chrome坚持显示该字段以前条目的下拉历史,这是删除标签框列表。
当前回答
2021年9月回答
当我不得不处理这个问题时,唯一稳定的解决方案是在<input>元素中每次呈现网站时为名称和自动完成属性生成一个随机字符串。
下面是一个使用纯JavaScript的简单演示。
Html:
<div>
<h3>Autofill disabled with random string</h3>
<form id="disable-autofill-form">
<div>
<span>First Name</span>
<input type="text" />
</div>
<div>
<span>Last Name</span>
<input type="text" />
</div>
<div>
<span>City</span>
<input type="text" />
</div>
<div>
<span>Street</span>
<input type="text" />
</div>
<div>
<span>Postal Code</span>
<input type="text" />
</div>
</form>
</div>
JavaScript:
const randomString = (Math.random() + 1).toString(36).substring(5);
const disableAutoFillForm = document.getElementById('disable-autofill-form');
const disableAutoFillFormInputs = [
...disableAutoFillForm.getElementsByTagName('input'),
];
disableAutoFillFormInputs.forEach((input) => {
input.setAttribute('autocomplete', randomString);
input.setAttribute('name', randomString);
});
你可以在这里找到一个Stackblitz项目。
其他回答
你可以使用autocomplete="new-password"
<input type="email" name="email">
<input type="password" name="password" autocomplete="new-password">
适用于:
Chrome: 53,54,55 火狐:48、49、50
经过大量的挖掘,我发现Chrome上的自动完成下拉菜单(版本83.0.4103.116)不显示,当我们删除输入标签上的名称和id属性 如。代码如下所示 < div > < span > 如果没有在输入标签上设置名称和id属性,则自动完成关闭工作 < input type = " text " / > < / span > < span > 自动完成将在这里工作,因为id属性已设置 <input id="name" type="text"/> < / span > < / div >
我有一个非常简单的解决方案,这个问题不需要代码和一个可接受的解决方案。Chrome经常读取输入的标签并自动完成。您可以简单地在标签中插入一个“空”字符。
E.g. <label>Surname</labe>
Becomes: <label>Sur‍name</label>
是“空字符串”的HTML转义字符。
这仍然会显示“姓氏”,但自动完成不会检测字段,并尝试自动完成它。
我已经找到了另一个解决方案-只是用style="-webkit-text-security: disc;"遮住你的autocomplete="off"输入中的字符。 你也可以像下面这样把它添加到你的CSS规则中:
[autocomplete="off"] {
-webkit-text-security: disc;
}
主要目标是从元素中消除type="password"或其他类似的类型属性。
至少在2021年1月24日,这个解决方案是有效的……
似乎Chrome现在忽略autocomplete="off",除非它是在<form autocomplete="off">标签。