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


当前回答

了解Firefox(我认为只有Firefox)使用了一个名为ismxfilld的值,该值基本上强制自动完成,这一点很重要。

ismxfilld=“0”表示关闭

or

ismxfilld=“1”表示开启

其他回答

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

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

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

最简单的答案是

<input autocomplete=“on | off”>

但请记住浏览器支持。当前,支持自动完成属性

铬17.0及最新版本IE 5.0及最新版本Firefox 4.0及最新版本Safari 5.2及最新版本Opera 9.6及最新版本

我正在四处寻找解决方案,但没有一个在所有浏览器上都能正常工作。

我尝试了自动完成off、none、nope、new_input_64(甚至是一些有趣的文本),因为autocomplete属性希望传递字符串,无论是什么。

经过多次搜索和尝试,我找到了这个解决方案。

我将所有输入类型都改为文本,并添加了一些简单的CSS代码。

以下是表格:

<form class="row gy-3">
  <div class="col-md-12">
    <label for="fullname" class="form-label">Full Name</label>
    <input type="text" class="form-control" id="fullname" name="fullname" value="">
  </div>
  <div class="col-md-6">
    <label for="username" class="form-label">User Name</label>
    <input type="text" class="form-control" id="username" name="username" value="">
  </div>
  <div class="col-md-6">
    <label for="email" class="form-label">Email</label>
    <input type="text" class="form-control" id="email" name="email" value="">
  </div>
  <div class="col-md-6">
    <label for="password" class="form-label">Password</label>
    <input type="text" class="form-control pswd" id="password" name="password" value="">
  </div>
  <div class="col-md-6">
    <label for="password" class="form-label">Confirm Password</label>
    <input type="text" class="form-control pswd" id="password" name="password" value="">
  </div>
  <div class="col-md-12">
    <label for="recaptcha" class="form-label">ReCaptcha</label>
    <input type="text" class="form-control" id="recaptcha" name="recaptcha" value="">
  </div>
</form>

隐藏密码的CSS代码:

.pswd {
    -webkit-text-security: disc;
}

在Chrome、Opera和Edge上测试。

在尝试了所有解决方案之后(有些解决方案部分奏效,禁用自动填充但不自动完成,有些根本不奏效),我找到了截至2020年的最佳解决方案,将type=“search”和autocomplete=“off”添加到输入元素中。这样地:

<input type="search" /> or <input type="search" autocomplete="off" />

还要确保表单元素具有autocomplete=“off”。这非常有效,并禁用自动完成和自动填充。

此外,如果您使用type=“email”或任何其他文本类型,则需要添加autocomplete=“new email”,这将完全禁用两者。type=“password”也是如此。只需将“new-”前缀与类型一起添加到自动完成中即可。这样地:

<input type="email" autocomplete="new-email" />
<input type="password" autocomplete="new-password" />

我遇到了同样的问题,今天2019年10月9日,我找到的唯一解决方案是

将autocomplete=“off”添加到表单标记中。

打开表单标签后输入1个错误。

<input id="username" style="display:none" type="text" name="fakeusernameremembered">

但它在密码类型字段上不起作用,请尝试

<input type="text" oninput="turnOnPasswordStyle()" placeholder="Enter Password" name="password" id="password" required>

在脚本上

function turnOnPasswordStyle() {
    $('#password').attr('type', "password");
}

这在Chrome-78、IE-44、Firefox-69上进行了测试