我创建了一个使用标签框下拉的web应用程序。除了Chrome浏览器(Version 21.0.1180.89),这在所有浏览器中都很有效。
尽管输入字段和表单字段都有autocomplete="off"属性,Chrome坚持显示该字段以前条目的下拉历史,这是删除标签框列表。
我创建了一个使用标签框下拉的web应用程序。除了Chrome浏览器(Version 21.0.1180.89),这在所有浏览器中都很有效。
尽管输入字段和表单字段都有autocomplete="off"属性,Chrome坚持显示该字段以前条目的下拉历史,这是删除标签框列表。
当前回答
自动完成=“关闭”不再工作。
尝试使用一个随机字符串来代替"Off",例如Autocomplete="NoAutocomplete"
我希望这能有所帮助。
其他回答
我不得不在drupal页面上用一个巨大的webform来解决这个问题。因为我不能编辑每个输入的html代码,所以我想出了下面的通用jQuery解决方案。
<script>
// Form Autocomplete FIX
function is_mobile() {
if( screen.width < 500 || navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) ) {
return true;
}
return false;
}
jQuery( 'input[autocomplete="off"]' ).each( function() {
if( is_mobile() ) {
return;
}
jQuery( this ).attr( 'readonly', true );
} );
jQuery( 'input[autocomplete="off"]' ).focus( function() {
if( is_mobile() ) {
return;
}
jQuery( this ).removeAttr( 'readonly' );
jQuery( this ).focus();
} );
jQuery( 'input[autocomplete="off"]' ).blur( function() {
if( is_mobile() ) {
return;
}
jQuery( this ).attr( 'readonly', true );
} );
</script>
浏览器检测从这里开始。
我想有可能优化这段代码(我很想获得一些建议),但您将从中获得想法。
在Chrome 48+使用这个解决方案:
Put fake fields before real fields: <form autocomplete="off"> <input name="fake_email" class="visually-hidden" type="text"> <input name="fake_password" class="visually-hidden" type="password"> <input autocomplete="off" name="email" type="text"> <input autocomplete="off" name="password" type="password"> </form> Hide fake fields: .visually-hidden { margin: -1px; padding: 0; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip: rect(0, 0, 0, 0); position: absolute; } You did it!
同样,这也适用于旧版本。
更新:08/2022
我设法让自动补全通过包含得到尊重
autocomplete="new-password"
在每个单独的输入元素上。
E.g.
<input id="email" type="email" autocomplete="new-password"/>
在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",所以我在触发提交之前把它们放回去。
似乎Chrome现在忽略autocomplete="off",除非它是在<form autocomplete="off">标签。