Reputation: 451
I have an HTML page with some button in it, i want my Objective C code to programmatically trigger that button so that i can get next response (NEXT HTML page)..
i am trying get and post method but i don't know where to change the html content and post it back..
HTML part of button is:
<input name="xyz" type="button" value="abc" onclick="validate(this.name)" >
is there any way to find where to change the html page post it back..?
and how this link help me..
How to Click A Button Programmatically - Button in WebBrowser ( IE )
NOTE : HTML page is some URL content in INTERNET, i want the next response, ie html page after clicking some button.
Upvotes: 1
Views: 7125
Reputation: 3399
You can use the following method to evaluate javascript with a UIWebView
object:
stringByEvaluatingJavaScriptFromString
:
So in your case:
If you have a UIWebView
object called webview:
NSString *jsStat = @"document.getElementsByName('xyz')[0].click()";
[webView stringByEvaluatingJavaScriptFromString:jsStat];
The method returns the result of the script;
Upvotes: 7
Reputation: 12671
if you are making ios app using objective-c then you need to use UIWebView for this purpose, and load your html in the UIWebView and using its delegate methods check if button is clicked something like this
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeFormSubmitted) {
// form is submitted or button is clicked , perform your actions here
}
return YES;
}
Upvotes: 1