Skip to content

Commit 5ab2e36

Browse files
authored
Merge pull request #276 from rydein/open_target_blank
fix No269: Can't load target="_blank" links on iOS
2 parents 59d155a + 81f378c commit 5ab2e36

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ios/Classes/FlutterWebviewPlugin.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
static NSString *const CHANNEL_NAME = @"flutter_webview_plugin";
44

55
// UIWebViewDelegate
6-
@interface FlutterWebviewPlugin() <WKNavigationDelegate, UIScrollViewDelegate> {
6+
@interface FlutterWebviewPlugin() <WKNavigationDelegate, UIScrollViewDelegate, WKUIDelegate> {
77
BOOL _enableAppScheme;
88
BOOL _enableZoom;
99
}
@@ -105,6 +105,7 @@ - (void)initWebview:(FlutterMethodCall*)call {
105105
}
106106

107107
self.webview = [[WKWebView alloc] initWithFrame:rc];
108+
self.webview.UIDelegate = self;
108109
self.webview.navigationDelegate = self;
109110
self.webview.scrollView.delegate = self;
110111
self.webview.hidden = [hidden boolValue];
@@ -260,6 +261,15 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigati
260261
}
261262
}
262263

264+
- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration
265+
forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures {
266+
267+
if (!navigationAction.targetFrame.isMainFrame) {
268+
[webView loadRequest:navigationAction.request];
269+
}
270+
271+
return nil;
272+
}
263273

264274
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
265275
[channel invokeMethod:@"onState" arguments:@{@"type": @"startLoad", @"url": webView.URL.absoluteString}];

0 commit comments

Comments
 (0)