wkWebView 点击链接无反应
多半是因为网页中有target="_blank" 在新窗口打开链接
而你有没有实现wkWebView的navigationDelegate的两个方法
//self.wkWebView.navigationDelegate = self; 设置代理
//实现navigationDelegate的两个方法
-(void)webView:(WKWebView*)webView decidePolicyForNavigationAction:(WKNavigationAction*)navigationAction decisionHandler:(void(^)(WKNavigationActionPolicy))decisionHandler{
//如果是跳转一个新页面
if(navigationAction.targetFrame ==nil) {
[webView loadRequest:navigationAction.request];
}
decisionHandler(WKNavigationActionPolicyAllow);
}
-(WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
{
NSLog(@"createWebViewWithConfiguration");
if (!navigationAction.targetFrame.isMainFrame) {
[webView loadRequest:navigationAction.request];
}
return nil;
}
网友评论