ソースを参照

feat(WKwebview): Allow _target links to be opened up in the same way as UIWebView. (#270)

Fixes #139
Benjos Antony 5 年 前
コミット
6643a8e38d
共有1 個のファイルを変更した11 個の追加0 個の削除を含む
  1. 11
    0
      ios/RNCWKWebView.m

+ 11
- 0
ios/RNCWKWebView.m ファイルの表示

@@ -73,6 +73,17 @@ static NSString *const MessageHanderName = @"ReactNative";
73 73
   return self;
74 74
 }
75 75
 
76
+/**
77
+ * See https://stackoverflow.com/questions/25713069/why-is-wkwebview-not-opening-links-with-target-blank/25853806#25853806 for details.
78
+ */
79
+- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
80
+{
81
+  if (!navigationAction.targetFrame.isMainFrame) {
82
+    [webView loadRequest:navigationAction.request];
83
+  }
84
+  return nil;
85
+}
86
+
76 87
 - (void)didMoveToWindow
77 88
 {
78 89
   if (self.window != nil && _webView == nil) {