我有一个文本输入和一个密码输入,Chrome 经常要求记住这些信息以便自动填充。问题是它不会自动填充该信息。
如何让它发挥作用?
这是一个单页应用程序,所有请求都是通过 AJAX 发出的。
因此,我的输入很简单:
<input type="text" placeholder="email" autocomplete="on" />
<input type="password" placeholder="password" autocomplete="on" />
我认为 autocomplete="on"
可以解决这个问题,但也许是因为我不使用表单?这可能是我的一个不好的做法,因为我所做的只是 Ajax 请求,但是我如何让它工作呢?
最佳答案
Chrome 解析表单以自动填充。所以你必须输入 <form>
元素周围,只要不添加提交输入元素,表单就不会打扰您。
另请参阅此答案:How to trigger Autofill in Google Chrome?
来自那个答案:
As pointed out in these insightful answers, all the regular expressions Chrome uses to identify/recognize common fields can be found in
autofill_regex_constants.cc.utf8
. So to answer the original question, just make sure the names for your html fields get matched by these expressions. Some examples include:
- 名字:
"first.*name|initials|fname|first$"
- 姓氏:
"last.*name|lname|surname|last$|secondname|family.*name"
- 电子邮件:
"e.?mail"
- 地址(第 1 行):
"address.*line|address1|addr1|street"
- 邮政编码:
"zip|postal|post.*code|pcode|^1z$"
关于javascript - 是什么让浏览器自动填充电子邮件/密码输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35597790/