Reputation: 141
I have a function/method in .html file and I need to call that function from objective C code. I have a page with UIWebView and we need to call and pass few parameters to javascript function in .html file. Please let me know if anybody has any answers. Thanks.
Upvotes: 0
Views: 2102
Reputation: 6268
Assuming you have a function like below in Javascript
function getTheName(id)
{
//Some stuff
return name;
}
You can call , pass parameters and get back a value from it like below
NSString *ID = @"THE_ID";
NSString *theJSMethod = [NSString stringWithFormat:@"getTheName('%@')", ID ];
NSString *returnedValueFromJSMethod = [yourWebViewInstance stringByEvaluatingJavaScriptFromString:theJSMethod];
Upvotes: 5