i have an example of a source code which programatically sets the value of fields in an HTML.
The part of the source code is as such:
- (void)viewDidLoad
{
[super viewDidLoad];
myWebView.delegate = self;
//---formulate the HTML string---
NSString *str = [[[NSString alloc] initWithString:
@"<html>"
" <body>"
" <h1>The fields below are filled in programmatically</h1>"
" <input id='username' value='UserName' />"
" <input id='password' value='Password' type='password' />"
" </body>"
"</html>"
] autorelease];
//---load the UIWebView with the html string---
[myWebView loadHTMLString:str baseURL:nil];
}
//---wait for the UIWebView to finish loading---
- (void)webViewDidFinishLoad:(UIWebView *)webView {
//---access the 2 fields in the HTML---
[myWebView stringByEvaluatingJavaScriptFromString:@"document.getElementById('username').value='Wei-Meng Lee';"];
[myWebView stringByEvaluatingJavaScriptFromString:@"document.getElementById('password').value='TopSecret';"];
}
I would like to programmatically set value of fields in an actually webpage like Facebook instead of a custom HTML like such written above.
How should i replace the “str” to an actual webpage’s html source code so that i can pick out the “ElementbyId”?
by replacing
with
[UIWebView loadRequest]and it will load the web view with the URL and the UIWebView will contain the HTML to makestringByEvaluatingJavaScriptFromStringwork.