[iOS] [Swift] WKWebViewでtarget=“_blank”に対応する
デリゲートを埋め込む
WKUIDelegate を埋め込む
class MyViewController: WKNavigationDelegate, WKUIDelegate {
}
_webview.uiDelegate をセットする
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.webView.uiDelegate = self
self.webView.navigationDelegate = self
}
webView:createWebViewWithConfiguration:メソッドを実装
対象URL(target=“_blank”)をSafariで開く
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
if navigationAction.targetFrame == nil {
if let url = navigationAction.request.url {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
return nil
}
Author And Source
この問題について([iOS] [Swift] WKWebViewでtarget=“_blank”に対応する), 我々は、より多くの情報をここで見つけました https://qiita.com/4q_sano/items/bf92f4ebf06d6bb1ead3著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .