如何初始化WKWebViewConfiguration?
我用cordova wkwebview开发混合应用程序,并编写了两个methoe初始化程序和webView
但我需要
configuration.preferences.javaScriptCanOpenWindowsAutomatically = YES;
WebView调用之前的value,所以我写了init方法 (https://developer.apple.com/documentation/webkit/wkwebview/1414998-init)
但是init方法不能在启动时调用
如何初始化configuration.preferences值
- init:(CGRect *)frame :(WKWebViewConfiguration *)configuration {
NSLog(@"init!!!!");
configuration.preferences.javaScriptEnabled = YES;
configuration.preferences.javaScriptCanOpenWindowsAutomatically = YES;
return nil;
}
- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
{
webView.navigationDelegate = self;
webView.UIDelegate = self;
webView.configuration.preferences.javaScriptEnabled = YES;
webView.configuration.preferences.javaScriptCanOpenWindowsAutomatically = YES;
if (navigationAction.request.URL) {
NSURL *url = navigationAction.request.URL;
NSString *urlPath = url.absoluteString;
if ([urlPath rangeOfString:@"https://"].location != NSNotFound || [urlPath rangeOfString:@"http://"].location != NSNotFound) {
[[UIApplication sharedApplication] openURL:url];
}
}
return nil;
}