禁用Chrome自动填入 [英] Disabling Chrome Autofill

查看:336
本文介绍了禁用Chrome自动填入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直运行到与几种形式的Chrome自动填入行为的问题。

I have been running into issues with the chrome autofill behavior on several forms.

在表单中的字段都有着非常普遍的,准确的名称,如电子邮件,名称或密码,他们也有自动完成=关闭设置。

The fields in the form all have very common and accurate names, such as "email", "name", or "password", and they also have autocomplete="off" set.

自动完成标志已成功禁用自动完成的行为,其中值的下拉列表显示为你开始打字,但一直没有改变,Chrome自动填充字段中的值。

The autocomplete flag has successfully disabled the autocomplete behavior, where a dropdown of values appear as you start typing, but has not changed the values that Chrome auto-populates the fields as.

除了铬充满着输入错误,例如使用电子邮件地址填写的手机输入这种行为将是确定的。客户抱怨这一点,所以它验证了多个案例中发生的事情,而不是像有些某种结果的东西,我已经在我的机器上本地完成。

This behavior would be ok except that chrome is filling the inputs incorrectly, for example filling the phone input with an email address. Customers have complained about this, so it's verified to be happening in multiple cases, and not as some some sort of result to something that I've done locally on my machine.

当前唯一解决方案,我能想到的是动态生成自定义输入名称,然后在后台提取值,但是这似乎是解决这个问题一个pretty哈克的方式。是否有改变,可以用来解决这个问题的自动填充行为的任何标记或怪癖?

The only current solution I can think of is to dynamically generate custom input names and then extract the values on the backend, but this seems like a pretty hacky way around this issue. Are there any tags or quirks that change the autofill behavior that could be used to fix this?

推荐答案

我刚刚发现,如果你有一个网站记住用户名和密码,Chrome浏览器的当前版本将自动填充您的用户名/电子邮件地址为前场的任何键入=密码字段。它不关心什么字段被称为 - 只是假设之前的密码将是您的用户名外地

I've just found that if you have a remembered username and password for a site, the current version of Chrome will autofill your username/email address into the field before any type=password field. It does not care what the field is called - just assumes the field before password is going to be your username.

旧的解决方案

只要使用<形式自动完成=关闭> 并prevents密码prefilling以及任何类型的字段启发式灌装基于假设一个浏览器可能使(这往往是错误的)。相对于使用<输入自动完成=关闭> 这似乎是pretty通过密码自动填充(Chrome中是非常忽视,火狐不服从它)。

Just use <form autocomplete="off"> and it prevents the password prefilling as well as any kind of heuristic filling of fields based on assumptions a browser may make (which are often wrong). As opposed to using <input autocomplete="off"> which seems to be pretty much ignored by the password autofill (in Chrome that is, Firefox does obey it).

更新的解决方案

镀铬现在忽略&LT;形式自动完成=关闭&GT; 。因此,我原来的解决方法(我已经删除)现在是风靡一时。

Chrome now ignores <form autocomplete="off">. Therefore my original workaround (which I had deleted) is now all the rage.

只需创建几个字段,并使其与隐藏显示:无。例如:

Simply create a couple of fields and make them hidden with "display:none". Example:

<!-- fake fields are a workaround for chrome autofill getting the wrong fields -->
<input style="display:none" type="text" name="fakeusernameremembered"/>
<input style="display:none" type="password" name="fakepasswordremembered"/>

然后把你的真实域下面。

Then put your real fields underneath.

记住要增加你的团队的评论或其他人会想知道你在做什么!

Remember to add the comment or other people on your team will wonder what you are doing!

更新2016年3月

刚刚与最新的Chrome测试 - 都很好。这现在是一个相当古老的答案,但我想只提我们的团队已经使用了好几年现在几十个项目。它仍然低于尽管一些评论的伟大工程。没有与无障碍没有问题,因为这些字段是显示:无这意味着他们没有得到焦点。正如我提到的,你需要把它们的的你真正的领域。

Just tested with latest Chrome - all good. This is a fairly old answer now but I want to just mention that our team has been using it for years now on dozens of projects. It still works great despite a few comments below. There are no problems with accessibility because the fields are display:none meaning they don't get focus. As I mentioned you need to put them before your real fields.

如果您使用的是JavaScript来修改你的表单,有一个额外的技巧,你将需要。显示假领域,而你正在操作的形式,然后再隐藏毫秒后。

If you are using javascript to modify your form, there is an extra trick you will need. Show the fake fields while you are manipulating the form and then hide them again a millisecond later.

使用jQuery实例code(假设你给你的假字段类):

Example code using jQuery (assuming you give your fake fields a class):

        $(".fake-autofill-fields").show();
        // some DOM manipulation/ajax here
        window.setTimeout(function () {
            $(".fake-autofill-fields").hide();
        },1);

这篇关于禁用Chrome自动填入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆