wkwebview a target="_blank" 打不开链接的解决方案

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了wkwebview a target="_blank" 打不开链接的解决方案相关的知识,希望对你有一定的参考价值。

- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
{
    //this is a ‘new window action‘ (aka target="_blank") > open this URL externally. If we´re doing nothing here, WKWebView will also just do nothing. Maybe this will change in a later stage of the ios 8 Beta
    if (!navigationAction.targetFrame) { 
        NSURL *url = navigationAction.request.URL;
        UIApplication *app = [UIApplication sharedApplication];
        if ([app canOpenURL:url]) {
            [app openURL:url];
        }
    }
    decisionHandler(WKNavigationActionPolicyAllow);
}

以上是关于wkwebview a target="_blank" 打不开链接的解决方案的主要内容,如果未能解决你的问题,请参考以下文章

WKWebView target="_blank" 链接在 safari ios11,swift 4 中打开新标签

iOS- "_OBJC_CLASS_$_WKWebView", referenced from: 解决记录

iOS WKWebview 没有响应 <a href="javascript:doSomething()" ...></a> 上的点击事件

iOS WkWebview不支持 window.open的解决方法

iOS WKWebView 加载本地图片报错"Not allowed to load local resource"

“WKWebView”类型的值没有成员“scrollView”