self.viewController.webView stringByEvaluatingJavaScriptFromString不起作用

时间:2016-01-20 09:57:28

标签: ios cordova uiwebview

NSString* jsString = [NSString stringWithFormat:@"alert('ok');"];[self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString];

我是在cordova appdelegate.m中写的!

2 个答案:

答案 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];