为什么WKWebView没有打开与target =" _blank"的链接? [英] Why is WKWebView not opening links with target="_blank"?

查看:502
本文介绍了为什么WKWebView没有打开与target =" _blank"的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WKWebView 不会打开任何 target =_ blank的链接又名在新窗口中打开属性在他们的HTML < a href> -Tag。

WKWebView does not open any links which have target="_blank" a.k.a. 'Open in new Window' attribute in their HTML <a href>-Tag.

推荐答案

我的解决方案是取消导航并再次使用loadRequest:加载请求。这将是类似于UIWebView的行为,它始终在当前帧中打开新窗口。

My solution is to cancel the navigation and load the request with loadRequest: again. This will be come the similar behavior like UIWebView which always open new window in the current frame.

首先,您需要实现 WKUIDelegate 。并将其设置为 _webview.UIDelegate 。然后实现:

First you need to have an implementation of WKUIDelegate. And set it to _webview.UIDelegate. Then implement:

- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
{

  if (!navigationAction.targetFrame.isMainFrame) {

    [webView loadRequest:navigationAction.request];
  }

  return nil;
}

这篇关于为什么WKWebView没有打开与target =&quot; _blank&quot;的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆