如何在主要浏览器中禁用特定输入(或表单字段)的自动完成?
当前回答
解决方法是在用户想要更改密码之前,不要将密码字段插入到DOM中。这可能适用于某些情况:
在我们的系统中,管理员页面中有一个密码字段,因此我们必须避免无意中设置其他用户的密码。由于这个原因,表单有一个额外的复选框,用于切换密码字段的可见性。
因此,在这种情况下,来自密码管理器的自动填充成为双重问题,因为用户甚至看不到输入。
解决方案是让复选框触发是否在DOM中插入密码字段,而不仅仅是其可见性。
AngularJS的伪实现:
<input type="checkbox" ng-model="createPassword">
<input ng-if="changePassword" type="password">
其他回答
固定的只需在实际输入字段上方添加
https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion-MDNhttps://medium.com/paul-jaworski/turning-off-autocomplete-in-chrome-ee3ff8ef0908-中等在EDGE、Chrome(最新版本63)、Firefox Quantum(57.0.4 64-бит)、Firefox(52.2.0)上测试假字段是chrome/opera自动填充错误字段的一种解决方法
const fakeInputStyle = {opacity: 0, float: 'left', border: 'none', height: '0', width: '0'}
<input type="password" name='fake-password' autoComplete='new-password' tabIndex='-1' style={fakeInputSyle} />
<TextField
name='userName'
autoComplete='nope'
...
/>
<TextField
name='password'
autoComplete='new-password'
...
/>
只需在输入中自动完成=“off”list=“autocompleteOff”,即可完成IE/Edge的工作!对于chrome,添加autocomplete=“新密码”
在这次谈话中,没有一个解决方案对我有效。
我终于找到了一个纯HTML解决方案,它不需要任何JavaScript,可以在现代浏览器中工作(除了Internet Explorer;至少要有一个捕获,对吗?),并且不需要对整个表单禁用自动完成。
只需关闭表单上的自动完成功能,然后为您希望在表单中工作的任何输入打开它。例如:
<form autocomplete="off">
<!-- These inputs will not allow autocomplete and Chrome
won't highlight them yellow! -->
<input name="username" />
<input name="password" type="password" />
<!-- This field will allow autocomplete to work even
though we've disabled it on the form -->
<input name="another_field" autocomplete="on" />
</form>
为字段使用非标准的名称和id,因此“name”不是“name_”。浏览器将不会将其视为名称字段。
最好的一点是,您可以对某些但不是所有字段执行此操作,并且它将自动完成某些但不是全部字段。
我已经解决了在页面加载后放置此代码的问题:
<script>
var randomicAtomic = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
$('input[type=text]').attr('autocomplete',randomicAtomic);
</script>