UIWebview 中的自动凭据输入 - iOS [英] Automatic credentials input in UIWebview - iOS
问题描述
我想创建一个具有以下功能的 iOS 应用程序 - 用户可以存储特定网站的用户名和密码,当访问该网站时,凭据将自动输入到 webview 中并自动提交.
I want to create an iOS app with a feature that - user can store username and password for particular website, and when the go to that website credentials will automatically typed in the webview and it will submitted automatically.
该概念已在应用中实现 - Dashlane
The concept is implemeted in the app - Dashlane
我知道这可以用 HTML 和 Javascript 来完成.但我不擅长 Javascript.任何人都可以请描述一下吗?举个例子就好了.
I know this can be done with HTML and Javascript. But I am not strong in Javascript. Can anyone please describe this ? It would be so kind of if you put some example.
假设有一个带有网址的网站 - http://www.quickeeme.com我的用户名是hamdaman",密码是123456".如何在 Web 视图中加载此 url,并在字段上自动填充此凭据?
Say there is a website with url - http://www.quickeeme.com and my username is "hamdaman" and password is "123456". How can I load this url in a Webview with autofill this credentials on the fields ?
推荐答案
这是我过去使用的一些代码,它允许我输入用户凭据并单击登录按钮.您需要将 sid
、pin
和 btnLogin
更改为您正在使用的网页上的相应变量(您可以使用例如,Chrome 中的查看源代码"):
Here is some code I used in the past that allowed me to enter user credentials and click a login button. You'll need to change sid
, pin
, and btnLogin
to the appropriate variables on the webpage you're using (you can find them using "View Source" in Chrome, for example):
//Write Javascript code in a string
NSString* javaScriptString = @"document.getElementById('sid').value='%@';"
"document.getElementById('pin').value='%@';"
"document.getElementById('btnLogin').click()";
//Insert string values into the Javascript string
javaScriptString = [NSString stringWithFormat:javaScriptString, yourUsername, yourPassword];
//Run Javascript in web view
[webView stringByEvaluatingJavaScriptFromString:javaScriptString];
这篇关于UIWebview 中的自动凭据输入 - iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!