简体   繁体   English

未触发 Chrome 信用卡自动填充

[英]Chrome credit card autofill not being triggered

I followed the advice given in this other Stack Overflow post and used a pattern found in the list of regexes used by Chrome , but for some reason Chrome is still not detecting that my field is a credit card field.我遵循了另一个 Stack Overflow 帖子中给出的建议,并使用了在Chrome 使用的正则表达式列表中找到的模式,但由于某种原因,Chrome 仍然没有检测到我的字段是信用卡字段。

Safari detects it just fine. Safari 检测到它就好了。

Here's the input HTML, as shown by the web inspector:这是输入 HTML,如网络检查器所示:

<input class="control" id="card_number" type="tel" name="card_number" 
    value="" autocorrect="off" spellcheck="off" autocapitalize="off"
    placeholder="Card number" data-reactid=".0.1.1.0.0.5.0.0" 
    x-autocompletetype="cc-number" autocompletetype="cc-number">

Yes, as you can see from the data-reactid , I am using React.是的,从data-reactid可以看出,我正在使用 React。 Maybe that has something to do with it.也许这与它有关。 Who knows!谁知道!

I've set up a test page so that others can play with it.我已经设置了一个测试页面,以便其他人可以使用它。 You can visit https://entire.life/payment-form-test in Safari, and (if you have autofill enabled and a credit card saved to it), it will pop up.您可以在 Safari 中访问https://entire.life/payment-form-test ,并且(如果您启用了自动填充并保存了信用卡),它将弹出。 If you visit it in Chrome, it will not pop up the autofill option.如果你在 Chrome 中访问它,它不会弹出自动填充选项。 Even after typing the first letter of your card.即使在输入卡的第一个字母之后。

This code is open source.此代码是开源的。 You can see the source for the /payment-form-test page here .您可以在此处查看/payment-form-test页面的来源。

It will work if you add following attributes to respective input elements:如果您将以下属性添加到相应的输入元素,它将起作用:

  • autocomplete="cc-number"
  • autocomplete="cc-exp"
  • autocomplete="cc-csc"

Also I noticed that Chrome will not autocomplete if one of the cc fields is missing.我还注意到,如果缺少 cc 字段之一,Chrome 将不会自动完成。

You can play around here - https://jsfiddle.net/q4gz33dg/2/你可以在这里玩 - https://jsfiddle.net/q4gz33dg/2/

Name your expiration fields card_expiry_month and card_expiry_year .将您的到期字段card_expiry_monthcard_expiry_year I'm not sure why your current names don't trigger the regex, but changing the names seems to work.我不确定为什么您当前的名称不会触发正则表达式,但更改名称似乎有效。

http://jsfiddle.net/7b6xtns7/ (it's a bit messy since it's not rendered) http://jsfiddle.net/7b6xtns7/ (有点乱,因为它没有渲染)

Edit: Looks like ordering has to do with it too.编辑:看起来订购也与它有关。 If that doesn't work try putting the month/date immediately after the number entry field如果这不起作用,请尝试将月份/日期紧跟在数字输入字段之后

http://jsfiddle.net/c86Lmo0L/ http://jsfiddle.net/c86Lmo0L/

The accepted answer is great, thought I'd just chime in with some documentation and a note regarding React (tagged for this question)..接受的答案很好,我想我只是附上一些文档和关于 React 的注释(标记为这个问题)..

React requires you to pass the attribute as autoComplete="cc-number" (note camelCase), otherwise it will default to autocomplete="off" . React 要求您将属性作为autoComplete="cc-number" (注意 camelCase)传递,否则它将默认为autocomplete="off"

More info:更多信息:

I can confirm that.我可以确认。 For instance, some websites only have autocomplete without any value as tag attribute.例如,一些网站只有自动完成功能,没有任何值作为标签属性。 By opening the web dev console ( CTRL + SHIFT + I ) I could jump to the element, double click the autocomplete tag to replace it autocomplete="cc-number" , and double click in the field to autocomplete the CC details by the opening selection dialog.通过打开 Web 开发控制台( CTRL + SHIFT + I ),我可以跳转到元素,双击自动完成标签以替换它autocomplete="cc-number" ,然后双击该字段以通过打开自动完成 CC 详细信息选择对话框。

All that alteration can still be much faster than fiddling with the credit card details from another app or physically holding the card .所有这些更改仍然比在另一个应用程序中修改信用卡详细信息或实际持有信用卡要快得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM