我创建了一个使用标签框下拉的web应用程序。除了Chrome浏览器(Version 21.0.1180.89),这在所有浏览器中都很有效。
尽管输入字段和表单字段都有autocomplete="off"属性,Chrome坚持显示该字段以前条目的下拉历史,这是删除标签框列表。
我创建了一个使用标签框下拉的web应用程序。除了Chrome浏览器(Version 21.0.1180.89),这在所有浏览器中都很有效。
尽管输入字段和表单字段都有autocomplete="off"属性,Chrome坚持显示该字段以前条目的下拉历史,这是删除标签框列表。
当前回答
Chrome一直在改变它在每个版本上处理自动完成的方式,我提出的方式是,使字段只读和onclick/focus使它非只读。试试这个jQuery片段。
jQuery(document).ready(function($){
//======fix for autocomplete
$('input, :input').attr('readonly',true);//readonly all inputs on page load, prevent autofilling on pageload
$('input, :input').on( 'click focus', function(){ //on input click
$('input, :input').attr('readonly',true);//make other fields readonly
$( this ).attr('readonly',false);//but make this field Not readonly
});
//======./fix for autocomplete
});
其他回答
Chrome一直在改变它在每个版本上处理自动完成的方式,我提出的方式是,使字段只读和onclick/focus使它非只读。试试这个jQuery片段。
jQuery(document).ready(function($){
//======fix for autocomplete
$('input, :input').attr('readonly',true);//readonly all inputs on page load, prevent autofilling on pageload
$('input, :input').on( 'click focus', function(){ //on input click
$('input, :input').attr('readonly',true);//make other fields readonly
$( this ).attr('readonly',false);//but make this field Not readonly
});
//======./fix for autocomplete
});
我设法禁用了利用这条规则的自动合成:
不是密码,但应该隐藏的字段,例如credit 卡号,也可以有type="password"属性,但应该 包含相关的自动补全属性,例如“cc-number”或 “cc-csc”。 https://www.chromium.org/developers/design-documents/create-amazing-password-forms
<input id="haxed" type="password" autocomplete="cc-number">
然而,随之而来的是巨大的责任:)
不要试图欺骗浏览器密码管理器(或内置于 浏览器,或外部)的设计是为了简化用户体验。 插入假字段,使用错误的自动补全属性或 利用现有密码管理器的弱点 只会让用户感到沮丧。
TL;DR:告诉Chrome这是一个新的密码输入,它不会提供旧的密码作为自动补全建议:
<input type="password" name="password" autocomplete="new-password">
由于设计决定,Autocomplete ="off"不起作用——大量研究表明,如果用户可以将密码存储在浏览器或密码管理器中,他们就会有更长时间和更难破解密码。
自动完成的规范已经改变,现在支持各种值,使登录表单更容易自动完成:
<!-- Auto fills with the username for the site, even though it's email format -->
<input type="email" name="email" autocomplete="username">
<!-- current-password will populate for the matched username input -->
<input type="password" autocomplete="current-password" />
如果你不提供这些Chrome浏览器仍然试图猜测,当它做它忽略autocomplete="off"。
解决方案是密码重置表单也存在自动完成值:
<label>Enter your old password:
<input type="password" autocomplete="current-password" name="pass-old" />
</label>
<label>Enter your new password:
<input type="password" autocomplete="new-password" name="pass-new" />
</label>
<label>Please repeat it to be sure:
<input type="password" autocomplete="new-password" name="pass-repeat" />
</label>
你可以使用autocomplete="new-password"标志告诉Chrome浏览器不要猜测密码,即使它已经为这个网站存储了一个。
Chrome还可以直接使用凭据API管理网站的密码,这是一个标准,最终可能会得到普遍支持。
我已经找到了另一个解决方案-只是用style="-webkit-text-security: disc;"遮住你的autocomplete="off"输入中的字符。 你也可以像下面这样把它添加到你的CSS规则中:
[autocomplete="off"] {
-webkit-text-security: disc;
}
主要目标是从元素中消除type="password"或其他类似的类型属性。
至少在2021年1月24日,这个解决方案是有效的……
自动完成=“关闭”不再工作。
尝试使用一个随机字符串来代替"Off",例如Autocomplete="NoAutocomplete"
我希望这能有所帮助。