【问题标题】:Which Attributes Does Chrome Autofill Expect?Chrome 自动填充期望哪些属性?
【发布时间】:2012-03-05 07:35:32
【问题描述】:

我希望将我们的网站与 Chrome 的地址自动填充功能联系起来,但我找不到任何关于它希望如何呈现表单的参考。

我猜它在表单的 name= 字段中寻找一些非常具体的东西,但是一个好的参考会很好,而不是必须对其进行逆向工程。

目前,Chrome 不会填写我们的任何表单,但 Safari 会填写大部分表单。冒着同时问两个问题的风险:有人也有 safari 的参考资料吗? Safari 似乎在使用我们的 title= 字段...

它不使用这个标准,是吗? http://www.ietf.org/rfc/rfc3106.txt

【问题讨论】:

标签: html google-chrome web autofill


【解决方案1】:

这个问题已经很老了,但我有一个 2017 年的更新答案!

现在有关于如何触发自动完成的完整文档。

Here's a link to the official current WHATWG HTML Standard for enabling autocomplete.

以下答案来自我的原始答案:https://stackoverflow.com/a/41965106/1696153

Google 写了一个pretty nice guide 用于开发对移动设备友好的网络应用程序。他们有一节介绍如何命名表单上的输入以轻松使用自动填充。尽管它是为移动设备编写的,但这适用于桌面和移动设备!

如何在您的 HTML 表单上启用自动完成功能

以下是有关如何启用自动完成功能的一些要点:

  • 为所有<input> 字段使用<label>
  • 将autocomplete 属性添加到您的<input> 标记并使用此guide 填写。
  • 为所有<input> 标签正确命名name 和autocomplete 属性
  • 示例:

    <label for="frmNameA">Name</label>
    <input type="text" name="name" id="frmNameA"
    placeholder="Full name" required autocomplete="name">
    
    <label for="frmEmailA">Email</label>
    <input type="email" name="email" id="frmEmailA"
    placeholder="name@example.com" required autocomplete="email">
    
    <!-- note that "emailC" will not be autocompleted -->
    <label for="frmEmailC">Confirm Email</label>
    <input type="email" name="emailC" id="frmEmailC"
    placeholder="name@example.com" required autocomplete="email">
    
    <label for="frmPhoneNumA">Phone</label>
    <input type="tel" name="phone" id="frmPhoneNumA"
    placeholder="+1-555-555-1212" required autocomplete="tel">
    

如何命名您的&lt;input&gt; 标签

为了触发自动完成功能,请确保在 &lt;input&gt; 标记中正确命名 name 和 autocomplete 属性。这将自动允许在表单上自动完成。确保也有&lt;label&gt;!也可以在here 找到此信息。

以下是如何命名您的输入:

  • 名字
    • 对 name 使用以下任意一种:name fname mname lname
    • 对 autocomplete 使用以下任意一种:
      • name(全名)
      • given-name(名字)
      • additional-name(中间名)
      • family-name(姓氏)
    • 示例:&lt;input type="text" name="fname" autocomplete="given-name"&gt;
  • 电子邮件
    • 对 name 使用以下任意一种:email
    • 对 autocomplete 使用以下任意一种:email
    • 示例:&lt;input type="text" name="email" autocomplete="email"&gt;
  • 地址
    • 对 name 使用其中任何一个:address city region province state zip zip2 postal country
    • 对 autocomplete 使用以下任意一种:
      • 对于一个地址输入:
        • street-address
      • 对于两个地址输入:
        • address-line1
        • address-line2
      • address-level1(州或省)
      • address-level2(城市)
      • postal-code(邮政编码)
      • country
  • 电话
    • 对 name 使用以下任意一种:phone mobile country-code area-code exchange suffix ext
    • 对 autocomplete 使用其中任何一个:tel
  • 信用卡
    • 对 name 使用以下任意一种:ccname cardnumber cvc ccmonth ccyear exp-date card-type
    • 对 autocomplete 使用以下任意一种:
      • cc-name
      • cc-number
      • cc-csc
      • cc-exp-month
      • cc-exp-year
      • cc-exp
      • cc-type
  • 用户名
    • 对 name 使用以下任意一种:username
    • 为 autocomplete 使用其中任何一个:username
  • 密码
    • 对 name 使用以下任意一种:password
    • 对 autocomplete 使用以下任意一种:
      • current-password(用于登录表格)
      • new-password(用于注册和密码更改表格)

资源

【讨论】:

【解决方案2】:

有很多东西可能是“预期的”(比如RFC3106 或hCard format 中的东西),但最终归结为你可以在Chromium source @987654325 中找到的东西@,我猜。

您可能对这个似乎是 Chromium's AutoFill implementation 的特定部分感兴趣,我通过使用 Google Code Search 功能 for Chromium 现在可以通过 Google Code Project Hosting 找到它。

一些用于正则表达式的constants are extern-ed 在autofill_regex_constants.h 中定义,并在autofill_regex_constants.cc.utf8 中以相当的extensive list 提供(即使支持I18N!)。

【讨论】:

    【解决方案3】:

    Chrome (v51.0) 似乎实现了以下规范:https://html.spec.whatwg.org/multipage/forms.html#autofill

    这意味着您可以使用 Chrome 应填写的特定类型的值填充 autocomplete 属性。

    示例:

    <input type="text" autocomplete="address-line1" id="a1" name="a1" />
    <input type="text" autocomplete="address-line2" id="a2" name="a2" />
    <input type="text" autocomplete="address-level2" id="city" name="city" />
    <input type="text" autocomplete="address-level1" id="state" name="state" />
    <input type="text" autocomplete="country-name" id="country" name="country" />
    
    <input type="text" autocomplete="tel" id="phone" name="phone" />
    <input type="text" autocomplete="email" id="email" name="email" />
    

    (显然我已经省略了示例中的标签)

    【讨论】:

      猜你喜欢
      • 2021-09-24
      • 1970-01-01
      • 2010-12-15
      • 2019-04-10
      • 2023-01-10
      • 1970-01-01
      • 1970-01-01
      • 2013-03-22
      相关资源
      最近更新 更多