self.viewController.webView stringByEvaluatingJava

2019-05-23 02:36发布

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

I wrote it in cordova appdelegate.m!

2条回答
男人必须洒脱
2楼-- · 2019-05-23 02:46

May want to try NSString* jsString = [NSString stringWithString:@"alert('ok');"];[self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString]; or NSString* jsString = @"alert('ok');"[self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString];

查看更多
唯我独甜
3楼-- · 2019-05-23 02:50

On cordova-ios@3.x you should be able to do:

[self.webView stringByEvaluatingJavaScriptFromString:jsString];

On cordova-ios@4+ you will need to cast the Webview class as it also supports WKWebView:

if ([self.webView isKindOfClass:[UIWebView class]]) {
    [(UIWebView*)self.webView stringByEvaluatingJavaScriptFromString:jsString];
}
查看更多
登录 后发表回答