webview某些超链接点击无响应的问题

出问题的超链接:

出门旅行想拍好建筑与城市,却不想背单反?其实只要一个手机就够了!

但是把链接换成以下就OK

安顺市区—大黑村—邢江河—竹海—傩雕人家—屯堡故事会—手工习作傩雕。

对比发现,有问题的链接是_blank标签,OK的链接是_self标签,因此需要对_blank标签进行适配

Android webView适配:重写onCreateWindow方法

  mWebView.setWebChromeClient(new WebChromeClient() {
         @Override
         public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
                WebView newWebView = new WebView(view.getContext());
                newWebView.setWebViewClient(new WebViewClient() {
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    // 在此处进行跳转URL的处理, 一般情况下_black需要重新打开一个页面,
                        CommonWebActivity.start(view.getContext(), url);
                        return true;
                    }

                });
                WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
                transport.setWebView(newWebView);
                resultMsg.sendToTarget();
                return true;
            }
        });

IOS适配(wkwebview):重写decidePolicyForNavigationAction方法

- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{
    NSURL *URL = navigationAction.request.URL;
    NSString *scheme = [URL scheme];
    if ([scheme isEqualToString:@"tel"]) {
        NSString *resourceSpecifier = [URL resourceSpecifier];
        NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@", resourceSpecifier];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
    }
     //判断是否开启新界面
    if (navigationAction.targetFrame == nil) {
        //手动跳转至新界面加载url
        [self gotoWebPage:URL.absoluteString];
        decisionHandler(WKNavigationActionPolicyAllow);
    }else{
        if ([URL.absoluteString containsString:@"http"] && ![URL.absoluteString containsString:_countryUrl]) {
            //注意,这里要取消action,否则会在原界面加载url                  
            decisionHandler(WKNavigationActionPolicyCancel);
            //手动跳转至新界面加载url
            [self gotoWebPage:URL.absoluteString];
        }
    }

    decisionHandler(WKNavigationActionPolicyAllow);
}

你可能感兴趣的:(webview某些超链接点击无响应的问题)