我创建了一个使用标签框下拉的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 49和迪奥戈Cid的解决方案不再工作了。
我做了一个不同的工作,在页面加载后在运行时隐藏和删除字段。
Chrome现在忽略了最初的解决方案应用凭据到第一个显示的类型=“密码”字段和它之前的类型=“文本”字段,所以我已经隐藏了两个字段使用CSS可见性:
<!-- HTML -->
<form>
<!-- Fake fields -->
<input class="chromeHack-autocomplete">
<input type="password" class="chromeHack-autocomplete">
<input type="text" placeholder="e-mail" autocomplete="off" />
<input type="password" placeholder="Password" autocomplete="off" />
</form>
<!-- CSS -->
.chromeHack-autocomplete {
height: 0px !important;
width: 0px !important;
opacity: 0 !important;
padding: 0 !important; margin: 0 !important;
}
<!--JavaScript (jQuery) -->
jQuery(window).load(function() {
$(".chromeHack-autocomplete").delay(100).hide(0, function() {
$(this).remove();
});
});
我知道这看起来不是很优雅,但很有效。
除了给它一个自动补全的假字段外,所有的解决方案都不起作用。我做了一个React组件来解决这个问题。
import React from 'react'
// Google Chrome stubbornly refuses to respect the autocomplete="off" HTML attribute so
// we have to give it a "fake" field for it to autocomplete that never gets "used".
const DontBeEvil = () => (
<div style={{ display: 'none' }}>
<input type="text" name="username" />
<input type="password" name="password" />
</div>
)
export default DontBeEvil
以下是我在Chrome版本51.0.2704.106上的工作方式。<input id="user_name" type="text" name="user_name" autocomplete="off" required /> And in combination with <input id="user_password" type="password" name="user_password" autocomplete="new-password" required />。我的问题是,在实现new-password之后,它仍然会在user_name字段上显示用户名的下拉列表。
更新
现在Chrome似乎忽略了style="display: none;"或style="visibility: hidden; "属性。
你可以把它改成这样:
<input style="opacity: 0;position: absolute;">
<input type="password" style="opacity: 0;position: absolute;">
根据我的经验,Chrome只自动完成第一个<input type="password">和前一个<input>。所以我添加了:
<input style="display:none">
<input type="password" style="display:none">
到<form>的顶部,该情况得到解决。
Autocomplete =off在现代浏览器中基本上被忽略了——主要是由于密码管理器等。
你可以尝试添加这个autocomplete="new-password",它不是所有浏览器都完全支持,但在一些浏览器上是有效的