我创建了一个使用标签框下拉的web应用程序。除了Chrome浏览器(Version 21.0.1180.89),这在所有浏览器中都很有效。
尽管输入字段和表单字段都有autocomplete="off"属性,Chrome坚持显示该字段以前条目的下拉历史,这是删除标签框列表。
我创建了一个使用标签框下拉的web应用程序。除了Chrome浏览器(Version 21.0.1180.89),这在所有浏览器中都很有效。
尽管输入字段和表单字段都有autocomplete="off"属性,Chrome坚持显示该字段以前条目的下拉历史,这是删除标签框列表。
当前回答
对于这个问题,我有一个近乎完美的解决方案: 从所有密码输入元素中删除"type=password",在所有这些元素都加载到DOM后,给一个超时来设置"type=password"。Chrome会忽略 改变类型为自动填充。例子:
setTimeout(()=>{ele.type="password"},3000)
或者通过事件改变类型:
ele.oninput=function(){ele.type="password"}
其他回答
Autocomplete =off在现代浏览器中基本上被忽略了——主要是由于密码管理器等。
你可以尝试添加这个autocomplete="new-password",它不是所有浏览器都完全支持,但在一些浏览器上是有效的
对于这个问题,我有一个近乎完美的解决方案: 从所有密码输入元素中删除"type=password",在所有这些元素都加载到DOM后,给一个超时来设置"type=password"。Chrome会忽略 改变类型为自动填充。例子:
setTimeout(()=>{ele.type="password"},3000)
或者通过事件改变类型:
ele.oninput=function(){ele.type="password"}
我发现这个解决方案是最合适的:
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;
}
在chrome v. 34之后,在<form>标记处设置autocomplete="off"不起作用
我做这些改变是为了避免这种恼人的行为:
删除密码输入的名称和id 在输入中放入一个类(例如:passwordInput)
(到目前为止,Chrome不会把保存的密码输入,但形式现在是破碎的)
最后,为了让表单工作,当用户点击提交按钮时,或者当你想触发表单提交时,运行以下代码:
var sI = $(".passwordInput")[0];
$(sI).attr("id", "password");
$(sI).attr("name", "password");
在我的情况下,我曾经在密码输入中有id="password" name="password",所以我在触发提交之前把它们放回去。