我一直在环顾四周,发现了很多用于自动填充的代码,如下所示:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//For Authentication
NSString *savedUsername = @"Bapu";
NSString *savedPassword = @"Bapu123";
if (savedUsername.length != 0 && savedPassword.length != 0)
{
//create js strings
NSString *loadUsernameJS = [NSString stringWithFormat:@"var inputFields = document.querySelectorAll(\"input[type='text']\"); \
for (var i = inputFields.length >>> 0; i--;) { inputFields[i].value = '%@';}", savedUsername];
NSString *loadPasswordJS = [NSString stringWithFormat:@"var inputFields = document.querySelectorAll(\"input[type='password']\"); \
for (var i = inputFields.length >>> 0; i--;) { inputFields[i].value = '%@';}", savedPassword];
//autofill the form
[webView stringByEvaluatingJavaScriptFromString: loadUsernameJS];
[webView stringByEvaluatingJavaScriptFromString: loadPasswordJS];
}
}
这就是我的 .m 文件中的内容,但是,当我转到 webView 时,这些字段仍然是空白的。关于为什么它不能填充的任何线索?
如果有帮助,我要填写的网站是:sis.ocsarts.net,相关代码是:
input type="text" size="20" name="UserName" value="" onkeydown="if (event.keyCode==13) { document.frmLogin.submit(); return false; };"
和
input type="password" size="20" name="Password" onkeydown="if (event.keyCode==13) { document.frmLogin.submit(); return false; };"
我的 FirstViewController.m 的完整代码是:
//
// FirstViewController.m
// OCSA
//
// Created by Jack Kearl on 4/1/13.
// Copyright (c) 2013 Jack Kearl. All rights reserved.
//
#import "FirstViewController.h"
@interface FirstViewController ()
@end
@implementation FirstViewController
@synthesize Aeries;
- (void)viewDidLoad
{
[super viewDidLoad];
[Aeries loadRequest:[NSURLRequest requestWithURL:
[NSURL URLWithString:@"http://sis.ocsarts.net/login.asp"]]];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//For Authentication
NSString *savedUsername = @"Bapu";
NSString *savedPassword = @"Bapu123";
if (savedUsername.length != 0 && savedPassword.length != 0)
{
//create js strings
NSString *loadUsernameJS = [NSString stringWithFormat:@"var inputFields = document.querySelectorAll(\"input[type='text']\"); \
for (var i = inputFields.length >>> 0; i--;) { inputFields[i].value = '%@';}", savedUsername];
NSString *loadPasswordJS = [NSString stringWithFormat:@"var inputFields = document.querySelectorAll(\"input[type='password']\"); \
for (var i = inputFields.length >>> 0; i--;) { inputFields[i].value = '%@';}", savedPassword];
//autofill the form
[webView stringByEvaluatingJavaScriptFromString: loadUsernameJS];
[webView stringByEvaluatingJavaScriptFromString: loadPasswordJS];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end