Subi
Subi

Reputation: 141

Calling javascript function from objectiveC

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

Answers (1)

sElanthiraiyan
sElanthiraiyan

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

Related Questions