如果你发现你的WKWebView中的网页,点击某个内容无反应时:
初始化:
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
WKPreferences *preferences = [[WKPreferences alloc] init];
//很重要,如果没有设置这个则不会回调createWebViewWithConfiguration方法,也不会回应window.open()方法
preferences.javaScriptCanOpenWindowsAutomatically = YES;
configuration.preferences = preferences;
#pragma mark -- WKUIDelegate
-(WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures{
NSLog(@"createWebViewWithConfiguration request %@",navigationAction.request);
if (!navigationAction.targetFrame.isMainFrame) {
[webView loadRequest:navigationAction.request];
}
if (navigationAction.targetFrame == nil) {
[webView loadRequest:navigationAction.request];
}
return nil;
}