我创建了一个使用标签框下拉的web应用程序。除了Chrome浏览器(Version 21.0.1180.89),这在所有浏览器中都很有效。
尽管输入字段和表单字段都有autocomplete="off"属性,Chrome坚持显示该字段以前条目的下拉历史,这是删除标签框列表。
我创建了一个使用标签框下拉的web应用程序。除了Chrome浏览器(Version 21.0.1180.89),这在所有浏览器中都很有效。
尽管输入字段和表单字段都有autocomplete="off"属性,Chrome坚持显示该字段以前条目的下拉历史,这是删除标签框列表。
当前回答
Chrome版本34现在忽略autocomplete=off, 看到这个。
很多关于这是好事还是坏事的讨论?你的观点是什么?
其他回答
这些方法都不再工作,chrome忽略所有这些属性,唯一的解决方案是使用jquery
在输入上使用这个
< onclick输入=“$”.removeAttr(readonly);attr(“readonly”,true);“readonly />
你可以使用autocomplete="new-password"
<input type="email" name="email">
<input type="password" name="password" autocomplete="new-password">
适用于:
Chrome: 53,54,55 火狐:48、49、50
我提出了以下解决方案,查询所有字段的属性autocomplple ="off",然后将其值设置为一个单独的空间,然后设置一个约200ms的定时器,并将值设置回一个空字符串。
例子:
// hack to prevent auto fill on chrome
var noFill = document.querySelectorAll("input[autocomplete=off]");
noFill.forEach(function(el) {
el.setAttribute("value", " ");
setTimeout(function() {
el.setAttribute("value", "");
}, 200);
});
我选择200毫秒作为计时器,因为经过一些实验,200毫秒似乎是我的电脑上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就绪后加载,或者在表单呈现后加载。
我找到了一个适合我的解决办法。它没有禁用自动完成,但允许自定义它。在Chrome 96, Opera 82测试
/* Change Autocomplete styles in Chrome*/
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill,
textarea:-webkit-autofill:hover,
textarea:-webkit-autofill:focus,
select:-webkit-autofill,
select:-webkit-autofill:hover,
select:-webkit-autofill:focus {
border: none;
border-bottom: 1px solid;
-webkit-text-fill-color: #000;
-webkit-box-shadow: 0 0 0 1000px transparent inset;
}