所以Safari在iOS8上提供了一个名为扫描信用卡的功能,适用于某些信用卡表单。
我的问题是,Safari是如何确定何时提供此选项的?
到目前为止,我发现这个选项在亚马逊和贝宝上可用,但我的所有信用卡输入表单都无法重现此行为。
所以Safari在iOS8上提供了一个名为扫描信用卡的功能,适用于某些信用卡表单。
我的问题是,Safari是如何确定何时提供此选项的?
到目前为止,我发现这个选项在亚马逊和贝宝上可用,但我的所有信用卡输入表单都无法重现此行为。
通过在iOS8浏览器和Chrome仿真中进行一些研究,我部分地弄清楚了它。我知道一些解决方案,但我不确定是否有其他方法可以实现。你将不得不感谢苹果在这方面提供的惊人缺乏文档。
目前Netflix / Amazon已经成功实现了信用卡扫描功能。因此,我在Chrome浏览器中模拟了一个iOS8用户代理,并检查了他们的信用卡号码字段的标记。以下是Netflix的:
<input name="cardNumber" smopname="num" id="cardNumber-CC" class="cardNumber" type="text" value="************0891" pattern="[0-9]*">
以下是亚马逊的:
<input name="addCreditCardNumber" size="20" maxlength="20">
placeholder
也能起作用。在占位符中出现“卡号”这个模式似乎也会触发自动填充。 - metahamza建议选择与信用卡相关的类型,大多数现代浏览器都会自动识别这些字段,包括移动版Safari和“扫描信用卡”功能。而且,在移动设备上,您始终可以得到正确的键盘。
示例(请注意autocomplete,x-autocompletetype和pattern属性):
<input type="text" id="cc-num" autocomplete="cc-number" x-autocompletetype="cc-number" pattern="\d*">
<input type="text" id="cc-name" autocomplete="cc-name" x-autocompletetype="cc-full-name">
除了Arnaud Brousseau的回答之外,在iOS模拟器文件中搜索“卡号”会得到以下文件:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/SafariShared.framework/SafariShared
对其进行strings
快速运行,可以发现以下字符串,这些字符串肯定用于匹配潜在的字段:
card number
cardnumber
cardnum
ccnum
ccnumber
cc num
creditcardnumber
credit card number
newcreditcardnumber
new credit card
creditcardno
credit card no
card#
card #
cvc2
cvv2
ccv2
security code
card verification
name on credit card
name on card
nameoncard
cardholder
card holder
name des karteninhabers
card type
cardtype
cc type
cctype
payment type
expiration date
expirationdate
expdate
再往前走一点:
month
date m
date mo
year
date y
date yr
这种天真的方法似乎没有涉及到哪些属性(id
,name
,placeholder
等等)或其他元数据(可能是标签?)实际上与此列表进行比较。另外,除了“name des karteninhabers”之外,这确实非常偏向英语,我认为这在苹果公司相当不寻常。
感谢 @barbazoo ,扫描信用卡选项将通过有效(非自签名)证书在 https 上可用。
cardExpirationYear
和cardExpirationMonth
被识别为id
属性。当年份和月份是带有适当ID的常规文本输入时,它可以正常工作。月份以2位数字形式填充,年份则以4位数字形式填充。在使用<select>标签进行快速测试时,我发现它也填充了正确的月份和年份。<input type="text" id="cardNumber" placeholder="CC number">
<select id="cardExpirationMonth">
<option value="01">01</option>
<option value="02">02</option>
...
<option value="11">11</option>
<option value="12">12</option>
</select>
<select id="cardExpirationYear">
<option value="2014">2014</option>
<option value="2015">2015</option>
...
<option value="2024">2024</option>
<option value="2025">2025</option>
</select>
autocomplete
。<label>Credit card number:
<input type=text autocomplete="cc-number">
</label>
<input type="text" autocomplete="[section-](optional) [shipping|billing](optional)
[home|work|mobile|fax|pager](optional) [autofill field name]">
<input type="text" name="foo" id="foo" autocomplete="section-red shipping mobile tel">
section-red : wrapping as a section. (named red)
shipping : shopping/billing
mobile : home|work|mobile|fax|pager (For telephone)
tel : [Tokens][2]
name
、id
或label
值。autocomplete
、id
和name
属性自动完成值。Browse Ver OS ID Name Autocomplete
Chrome 50 OS X 10.11.4 No Yes Yes
Opera 35 OS X 10.11.4 No Yes Yes
Firefox 46 OS X 10.11.4 Yes Yes No
Edge 25 Windows 10 No Yes No
Safari 9.1 OS X 10.11.4 Partial Partial Partial
Safari 9 iOS 9.3.1 Partial Partial Partial
这里涉及到更多的事情。我强烈推荐我提到的博客。
我发现这样的方法可以工作,但我认为这是一个非常丑陋的解决方案,因为它依赖于在label
标签之间实际显示的文本:
<html>
<head>
<title>AutoFill test</title>
</head>
<body>
<h1>AutoFill test</h1>
<h2>revision 4</h2>
<form action="#">
<input type="text" name="cardNumber" id="id1"> <label for="id1">Number</label><br>
<input type="text" name="cardName" id="id2"> <label for="id2">Name on card</label><br>
<label>Expiration date</label>
<input type="text" name="expirationMonth" id="id3" maxlength="2">
<input type="text" name="expirationYear" id="id4" maxlength="2"><br>
<input type="text" name="csc" id="5"> <label for="id5">CSC</label><br>
</form>
</body>
</html>
我不是完全确定,但我认为name
参数并不重要。
cardName
更改为yyy
,它起作用了。(没有尝试操作其他内容。) - gklka<label style="opacity:0.01;color:#FFF;font-size:2pt;">Card Number</label>
不透明度为0或字体大小为1pt可以防止iOS提供该选项。今天早上升级到iOS 8.1.3后,所有的东西都坏了。在iOS 8.1.2上时上述所有内容都可以正常工作 - 现在扫描信用卡的键盘选项根本就没有出现。这是我的代码,昨天在iOS 8.1.2上可以工作,但今天在iOS 8.1.3上无法工作:
<html>
<head>
<title>Scan credit card using iOS 8</title>
<style type="text/css">
input {height:1.5em;width:95%}
input[type="number"] {font-size: 2.5em}
body {background-color:lightgray;font-size: 3em;font-family: sans-serif;}
#purchase {font-size: 2em;font-weight: bold;height:1.2em}
</style>
</head>
<body>
<form action="https://yoursite.com/credit-card-purchase" method="POST">
Credit Card Number 1<br />
<input type="number" autocomplete="cc-number" name="cardNumber" id="cardNumber" value="" placeholder="*** **** *** ****" />
<br />
Expiry month <br />
<input type="number" name="expirationMonth" id="cardExpirationMonth" />
<br />
Expiry year <br />
<input type="number" name="expirationYear" id="cardExpirationYear" />
<br />
<br />
<input type="submit" value="Purchase" id="purchase">
</form>
</head>
</html>