是否可以使用UITextFields中的用户名和密码信息自动登录UIWebView中的网站? [英] Can I use username and password information from UITextFields to log onto a website in a UIWebView automatically?

查看:69
本文介绍了是否可以使用UITextFields中的用户名和密码信息自动登录UIWebView中的网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试找到解决此问题的方法.本质上,我有一个初始的UIView,询问特定站点的用户名和密码,然后此信息将传递到下一个具有UIWebView的视图中.我想知道是否可以自动在网站上填写用户名和密码详细信息,并将用户直接发送到网站上的帐户页面.

I am currently trying to find a solution to this task. Essentially I have an initial UIView that asks for the users username and password for a specific site, this information would then get past onto the next view which has a UIWebView inside. I would like to know if its possible to automatically fill in the username and password details on the site and send the user directly to their account page on the site.

谢谢.

推荐答案

假定您的网站具有div标签,您可以使用stringByEvaluatingJavsScriptFromString插入.

assuming your website has div tags you can inject using stringByEvaluatingJavsScriptFromString.

此示例将用户名注入Twitter的注册页面.您可以通过将其加载到viewDidLoad中进行测试:

This example injects a username into the twitter sign up page. You can test it by loading this in your viewDidLoad:

NSString *urlString = @"https://mobile.twitter.com/signup";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];

,然后在webViewDidFinishLoad中注入用户名:

and then in webViewDidFinishLoad inject the username:

- (void)webViewDidFinishLoad:(UIWebView *)webView;
{
[webView stringByEvaluatingJavaScriptFromString:@"var field = document.getElementById('oauth_signup_client_fullname');"  
 "field.value='yourUserName';"];  
}

对不起,您刚刚意识到您已经有了解决方案,但是却错过了实现.希望以上内容能对您有所帮助.

sorry, just realised you already had the solution but were missing the implementation. Hope the above helps.

btw将动态变量添加到注入的javascript中:

btw to add a dynamic variable into the injected javascript use:

- (void)webViewDidFinishLoad:(UIWebView *)webView;
{

    NSString *injectedVariable = @"userNameHere";

    NSString *injectedString = [NSString stringWithFormat:@"var field = document.getElementById('oauth_signup_client_fullname'); field.value='%@';", injectedVariable];

[webView stringByEvaluatingJavaScriptFromString:injectedString];  
}

这篇关于是否可以使用UITextFields中的用户名和密码信息自动登录UIWebView中的网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆