我创建了一个使用标签框下拉的web应用程序。除了Chrome浏览器(Version 21.0.1180.89),这在所有浏览器中都很有效。
尽管输入字段和表单字段都有autocomplete="off"属性,Chrome坚持显示该字段以前条目的下拉历史,这是删除标签框列表。
我创建了一个使用标签框下拉的web应用程序。除了Chrome浏览器(Version 21.0.1180.89),这在所有浏览器中都很有效。
尽管输入字段和表单字段都有autocomplete="off"属性,Chrome坚持显示该字段以前条目的下拉历史,这是删除标签框列表。
当前回答
我刚刚尝试了下面的方法,它似乎在Chrome 53上起了作用——当输入密码字段时,它还禁用了“使用密码用于:”下拉菜单。
简单地设置你的密码输入类型为文本,然后添加onfocus处理程序(内联或通过jQuery/vanilla JS)来设置类型为密码:
onfocus="this.setAttribute('type','password')"
或者更好:
onfocus="if(this.getAttribute('type')==='text') this.setAttribute('type','password')"
其他回答
我在我的表单中的一个搜索字段也有类似的问题。无论是autocomplete= "false"还是autocomplete= "off"都不适合我。结果是,当你有aria-label属性在输入元素是设置为一些像城市或地址或类似的东西,chrome覆盖你所有的设置和显示自动完成无论如何
所以修复我所做的是从aria标签中删除城市部分,并提出一个不同的值。最后自动完成停止显示
基本上我们可以摆脱任何文本框的自动完成从chrome, firefox或任何类型的浏览器。这是简单的javascript。
window.onload=function(){
setTimeout(function(){
document.getElementById('username').value = '';
document.getElementById('password').value = '';
},100);
}
当你的窗口完成加载,100毫秒后,我们的用户名和密码字段的值将被删除。 我认为这是最好的方法做自动完成在所有浏览器(特别是chrome)。
写一个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>
我发现了一个窍门:
<input type="password" id="some_id" name="some_name" value=" " placeholder="Password">
<script>
$(function)
{
$("#some_id").val("");
}
</script>
注意,value是空格。它防止自动堆积在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项目。