根据this answer on another similar question,您需要实施UIWebView
委托方法webViewDidFinishLoad:
,并在那里执行[myWebView stringByEvaluatingJavaScriptFromString:@"myJavaScriptCode()"]
。
为了实现此目的,您需要在UIWebView
实例上设置委托并实现上述的委托方法,以便在加载页面后执行JavaScript。
- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
can be found here的文档。
现在针对您的问题的其他部分(谢谢澄清!)..在Objective-C中连接字符串时,可以使用NSString
类方法stringWithFormat:
。
例如,通过两项Objective-C的值,以一个JavaScript字符串,你可以做这样的事情:
// Substitute your Objective-C values into the string
NSString *javaScript = [NSString stringWithFormat:@"setVars('%@', '%@')", var1, var2, nil];
// Make the UIWebView method call
NSString *response = [webViewA stringByEvaluatingJavaScriptFromString:javaScript];
谁想要在UIWebView中的Javascript运行的话题优雅的演示人,请参考到:http://creiapp.blogspot.hk/2013/04/uiwebview-javascript.html – 2013-04-18 05:43:08