如何禁用 Chrome 自动填充用户名/电子邮件密码?

新手上路,请多包涵

我知道它在 SO 上被回答了很多次,但那是针对旧版本的 Chrome。

我有 Chrome 版本 53.0.2785.143。

我想禁用 Chrome 自动填充密码字段,

我已经尝试了旧 SO 答案中提到的所有方法,

方法一:

尝试使用虚假的用户名密码。

 <input style="display:none" type="text" name="fakeusernameremembered"/>
<input style="display:none" type="password" name="fakepasswordremembered"/>

方法二:

尝试使用 autocomplete='new-password'autocomplete='false'autocomplete='off'

但它们都不起作用。

原文由 Umair Ayub 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 458
1 个回答

试试这个 display:none

 <input type="text" name="prevent_autofill" id="prevent_autofill" value="" style="display:none;" />
<input type="password" name="password_fake" id="password_fake" value="" style="display:none;" />
<input type="password" name="password" id="password" value="" />

您也可以使用 jQuery 来解决这个问题,希望这对您有所帮助,如果没有请在这里发表评论,祝您好运:)

更新:

这取决于 chrome 版本,有时这不适用于 chrome 新版本,所以你应该尝试很多事情来防止这个问题,也试试这些代码片段,请评论发生了什么:)

方案二

$('form[autocomplete="off"] input, input[autocomplete="off"]').each(function () {

                var input = this;
                var name = $(input).attr('name');
                var id = $(input).attr('id');

                $(input).removeAttr('name');
                $(input).removeAttr('id');

                setTimeout(function () {
                    $(input).attr('name', name);
                    $(input).attr('id', id);
                }, 1);
            });

它从元素中删除“name”和“id”属性,并在 1 毫秒后将它们分配回来。把这个放在文档中准备好。

解决方案 3

 <input type="text" name="email">
<input type="password" name="password" autocomplete="new-password">

在 Chrome 53 中测试并工作

解决方案 4

尝试 autocomplete="false" 而不是 autocomplete="off"nofill

原文由 Sachith Wickramaarachchi 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题