self.viewController.webView stringByEvaluatingJavaScriptFromString does not work

丶灬走出姿态 提交于 2019-12-08 02:43:27

问题


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

I wrote it in cordova appdelegate.m!


回答1:


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];
}



回答2:


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



来源:https://stackoverflow.com/questions/34896815/self-viewcontroller-webview-stringbyevaluatingjavascriptfromstring-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!