From 27882ade6977aa1855fe2d2f0788422ed868c69d Mon Sep 17 00:00:00 2001 From: Jeffrey Lim Date: Tue, 4 Feb 2020 14:44:47 +0800 Subject: [PATCH] Fix FlutterWebView not opening href with target="_blank" --- .../webview_flutter/ios/Classes/FlutterWebView.h | 2 +- .../webview_flutter/ios/Classes/FlutterWebView.m | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/webview_flutter/ios/Classes/FlutterWebView.h b/packages/webview_flutter/ios/Classes/FlutterWebView.h index 627790186dac..875551d3535d 100644 --- a/packages/webview_flutter/ios/Classes/FlutterWebView.h +++ b/packages/webview_flutter/ios/Classes/FlutterWebView.h @@ -7,7 +7,7 @@ NS_ASSUME_NONNULL_BEGIN -@interface FLTWebViewController : NSObject +@interface FLTWebViewController : NSObject - (instancetype)initWithFrame:(CGRect)frame viewIdentifier:(int64_t)viewId diff --git a/packages/webview_flutter/ios/Classes/FlutterWebView.m b/packages/webview_flutter/ios/Classes/FlutterWebView.m index 20aad2c593ff..5e3456d50e49 100644 --- a/packages/webview_flutter/ios/Classes/FlutterWebView.m +++ b/packages/webview_flutter/ios/Classes/FlutterWebView.m @@ -93,6 +93,7 @@ - (instancetype)initWithFrame:(CGRect)frame _webView = [[FLTWKWebView alloc] initWithFrame:frame configuration:configuration]; _navigationDelegate = [[FLTWKNavigationDelegate alloc] initWithChannel:_channel]; + _webView.UIDelegate = self; _webView.navigationDelegate = _navigationDelegate; __weak __typeof__(self) weakSelf = self; [_channel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { @@ -398,4 +399,17 @@ - (void)updateUserAgent:(NSString*)userAgent { } } +#pragma mark WKUIDelegate + +- (WKWebView*)webView:(WKWebView*)webView + createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration + forNavigationAction:(WKNavigationAction*)navigationAction + windowFeatures:(WKWindowFeatures*)windowFeatures { + if (!navigationAction.targetFrame.isMainFrame) { + [webView loadRequest:navigationAction.request]; + } + + return nil; +} + @end