Browse Source

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

Fixes #139
Benjos Antony 5 years ago
parent
commit
6643a8e38d
1 changed files with 11 additions and 0 deletions
  1. 11
    0
      ios/RNCWKWebView.m

+ 11
- 0
ios/RNCWKWebView.m View File

@@ -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) {