Can a view controller interact with the HTML elements contained in a web page that's rendered by a UIWebView? Is there any access to the DOM, like there is in a C# form and a contained WebControl?
+1
A:
DOM API is not available. You can call a Javascript function from Objective-C by using stringByEvaluatingJavaScriptFromString.
To get the value of an input field named "fname":
NSString * fString =[webView stringByEvaluatingJavaScriptFromString:@"document.getElementByName(\"fname\").value"];
NSLog(@"fString: %@",fString);
Shaji
2010-07-08 14:07:07
So if my page contains the following:<form action="form_action.asp" method="get"> First name: <input type="text" name="fname" /><br /> Last name: <input type="text" name="lname" /><br /> <input type="submit" value="Submit" /></form>How would I access the first name field from the view controller using Javascript?
jkally
2010-07-08 18:17:11
@jkally I have updated the answer.
Shaji
2010-07-08 19:36:11
Thanks shaji. Very good answer.
jkally
2010-07-08 20:38:20