我创建了一个使用标签框下拉的web应用程序。除了Chrome浏览器(Version 21.0.1180.89),这在所有浏览器中都很有效。
尽管输入字段和表单字段都有autocomplete="off"属性,Chrome坚持显示该字段以前条目的下拉历史,这是删除标签框列表。
我创建了一个使用标签框下拉的web应用程序。除了Chrome浏览器(Version 21.0.1180.89),这在所有浏览器中都很有效。
尽管输入字段和表单字段都有autocomplete="off"属性,Chrome坚持显示该字段以前条目的下拉历史,这是删除标签框列表。
当前回答
我发现这个解决方案是最合适的:
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就绪后加载,或者在表单呈现后加载。
其他回答
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项目。
对于这个问题,我使用了这个css解决方案。这对我很有用。
input{
text-security:disc !important;
-webkit-text-security:disc !important;
-moz-text-security:disc !important;
}
我使用Chrome -版本64.0.3282.140(正式版本)(64位),并使用以下代码和表单名称,它适用于我。
<form name="formNameHere">....</form>
<script type="text/javascript">
setTimeout(function(){
document.formNameHere.reset();
},500);
</script>
Autocomplete ="off"现在工作了,所以你可以做以下事情:
<input id="firstName2" name="firstName2" autocomplete="off">
在当前的Chrome 70以及从Chrome 62开始的所有版本中测试。
演示:
顶部输入具有自动完成工作 底部输入通过添加autocomplete="off"来禁用自动完成
写一个2020年以上的答案,如果这对任何人都有帮助的话。我尝试了上面的许多组合,但在我的案例中,有一个关键的组合是缺失的。即使我一直保持autocomplete="nope"一个随机字符串,它并不为我工作,因为我有name属性缺失!
所以我保留了name='password' And autocomplete = "new-password"
对于用户名,我保留了name="usrid" //不要保留包含'用户'的字符串
and autocomplete = "new-password" //也一样,所以谷歌停止建议密码(管理密码下拉菜单)
这对我来说非常有效。 (我为Cordova/ionic使用的Android和iOS web视图做到了这一点)
<ion-input [type]="passwordType" name="password" class="input-form-placeholder" formControlName="model_password"
autocomplete="new-password" [clearInput]="showClearInputIconForPassword">
</ion-input>