Reputation:
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.
The concept is implemeted in the app - Dashlane
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.
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 ?
Upvotes: 0
Views: 878
Reputation: 8576
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];
Upvotes: 1