如何在主要浏览器中禁用特定输入(或表单字段)的自动完成?


当前回答

当我自己尝试时,事情已经改变了,旧的答案不再有效。

我确信它会奏效。我在Chrome、Edge和Firefox中测试了这一功能,它确实做到了这一点。你也可以尝试一下,告诉我们你的经历。

set the autocomplete attribute of the password input element to "new-password"

<form autocomplete="off">
....other element
<input type="password" autocomplete="new-password"/>
</form>

这是根据MDN

如果您正在定义一个用户管理页面,用户可以在该页面中为另一个人指定新密码,因此您希望防止自动填充密码字段,则可以使用autocomplete=“新密码”

这是一个提示,哪些浏览器不需要遵守。然而,由于这个原因,现代浏览器已经停止使用autocomplete=“new password”自动填充<input>元素。

其他回答

我真不敢相信,这件事被报道了这么久,仍然是一个问题。以前的解决方案对我来说不起作用,因为Safari似乎知道元素何时不显示或不在屏幕上,但下面的解决方案确实对我起作用:

<div style="height:0px; overflow:hidden; ">
  Username <input type="text" name="fake_safari_username" >
  Password <input type="password" name="fake_safari_password">
</div>

许多现代浏览器不再支持登录字段的autocomplete=“off”。autocomplete=“新密码”是wokring,更多信息MDN文档

对于React,您可以尝试将此代码放在表单下面或密码输入上面,或者放在电子邮件和密码输入之间

export const HackRemoveBrowsersAutofill = () => (
  <>
    <input type="email" autoComplete="new-password" style={ { display: 'none' } } />
    <input type="password" autoComplete="new-password" style={ { display: 'none' } } />
  </>
)

示例之一:

<input type="email"/>
<HackRemoveBrowsersAutofill/>
<input type="password"/>

如果您想阻止通用浏览器插件LastPass自动填充字段,可以将属性数据lpignore=“true”添加到此线程的其他建议中。请注意,这不仅适用于密码字段。

<input type="text" autocomplete="false" data-lpignore="true" />

前一段时间我也在尝试做同样的事情,但被难住了,因为我发现的所有建议都不适合我。结果是LastPass。

为了解决这个问题,我使用了一些CSS技巧和以下工作。

input {
    text-security:disc;
    -webkit-text-security:disc;
    -mox-text-security:disc;
}

请阅读本文了解更多详情。