create js file demo.js and add code
var hello = function(str){ return str; };
add UIWebView => Paste JavaScript in a dummy html file and load it into UIWebView
[self.webView loadHTMLString:@"<script src=\"demo.js\"></script>" baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]]];
Here is the code to make a JS call
NString * str=@ "hi JavaScript"; NSString *function = [[NSString alloc] initWithFormat: @"hello(%@)", str]; NSString *result = [webView stringByEvaluatingJavaScriptFromString:function];
You now have one important safety tip for this to really work: UIWebView should actually load the view. It should not be visible, but for the WebKit engine to run JS, it must be in the view.
source share