小编at0*_*m87的帖子

使用JavaScript在UIWebView中查找和自动填充HTML登录表单

我有一个UIWebView,它像一个互联网浏览器,并加载它所在的网页的HTML.

在webViewController中,方法webViewDidFinishLoad,当网页在UIWebView上完成加载时,会从网页加载HTML.

从HTML我想筛选出文本字段,以便使用我的数据库中存储的值来促进该文本字段的自动填充.

有什么办法吗?该方法应该能够在所有网站上工作.

在UIWebView中为文本字段设置文本几乎可以帮助我,但我已经尝试过,文本字段永远不会被填充.

在登录页面中将有两个文本字段,所以我尝试使用

document.getElementsByTagName('INPUT')[0].value
document.getElementsByTagName('INPUT')[1].value 
Run Code Online (Sandbox Code Playgroud)

输入值但没有魔法.

编辑:我已尝试在阵列中的其他位置.Facebook的用户名和密码是[3]和[4],而亚马逊则是[11]和[14].所以字段使用上述方法的位置有点随机.任何其他适用于所有网站的建议?

Edit2:我可以试试

document.getElementsById('id_name').value
Run Code Online (Sandbox Code Playgroud)

但ID方法不适用于我,因为我需要一种通用方法来识别任何网站上的文本字段(所有网站使用不同的ID名称)

在我看来,有些网站一直为用户名设置tabindex ="1",密码为tabindex ="2".

例如在Facebook这样的网页中:

<input type="text" class="inputtext" name="email" id="email" value="" tabindex="1" />
<input type="password" class="inputtext" name="pass" id="pass" tabindex="2" /> 
Run Code Online (Sandbox Code Playgroud)

亚马逊:

<input id="ap_email" name="email" value="" type="email" size="30" maxlength="128" tabindex="1" autocorrect="off" autocapitalize="off" />
<input id="ap_password" name="password" type="password" maxlength="1024" size="20"  tabindex="2" onkeypress="displayCapsWarning(event,'ap_caps_warning', this);" class="password"/> 
Run Code Online (Sandbox Code Playgroud)

dbs银行:

<input type="text" tabindex="1" maxlength="20" size="32" name="UID" id="UID">
<input type="password" onkeyup="keyUp(event)" onkeydown="return onlyNumerics(event)" tabindex="2" maxlength="9" size="32" name="PIN" id="PIN" autocomplete="off">
Run Code Online (Sandbox Code Playgroud)

但我没有在谷歌看到这个tabindex:

<input …
Run Code Online (Sandbox Code Playgroud)

html javascript textfield uiwebview ios

11
推荐指数
2
解决办法
1万
查看次数

标签 统计

html ×1

ios ×1

javascript ×1

textfield ×1

uiwebview ×1