NSString* jsString = [NSString stringWithFormat:@"alert('ok');"];[self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString];
我是在cordova appdelegate.m中写的!
答案 0 :(得分:9)
在cordova-ios@3.x上你应该可以:
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
在cordova-ios @ 4 +上你需要转换Webview类,因为它也支持WKWebView:
if ([self.webView isKindOfClass:[UIWebView class]]) {
[(UIWebView*)self.webView stringByEvaluatingJavaScriptFromString:jsString];
}
答案 1 :(得分:0)
可能想尝试NSString* jsString = [NSString stringWithString:@"alert('ok');"];[self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString];
或NSString* jsString = @"alert('ok');"[self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString];