onCreateWindow property
Event fired when the WebView requests the host application to create a new window,
for example when trying to open a link with target="_blank"
or when window.open()
is called by JavaScript side.
If the host application chooses to honor this request, it should return true
from this method, create a new WebView to host the window.
If the host application chooses not to honor the request, it should return false
from this method.
The default implementation of this method does nothing and hence returns false
.
createWindowAction
represents the request.
NOTE: to allow JavaScript to open windows, you need to set InAppWebViewOptions.javaScriptCanOpenWindowsAutomatically option to true
.
NOTE: on Android you need to set AndroidInAppWebViewOptions.supportMultipleWindows option to true
.
Also, if the request has been created using JavaScript (window.open()
), then there are some limitation: check the NavigationAction class.
NOTE: on iOS, setting these initial options: InAppWebViewOptions.supportZoom, InAppWebViewOptions.useOnLoadResource, InAppWebViewOptions.useShouldInterceptAjaxRequest,
InAppWebViewOptions.useShouldInterceptFetchRequest, InAppWebViewOptions.applicationNameForUserAgent, InAppWebViewOptions.javaScriptCanOpenWindowsAutomatically,
InAppWebViewOptions.javaScriptEnabled, InAppWebViewOptions.minimumFontSize, InAppWebViewOptions.preferredContentMode, InAppWebViewOptions.incognito,
InAppWebViewOptions.cacheEnabled, InAppWebViewOptions.mediaPlaybackRequiresUserGesture,
InAppWebViewOptions.resourceCustomSchemes, IOSInAppWebViewOptions.sharedCookiesEnabled,
IOSInAppWebViewOptions.enableViewportScale, IOSInAppWebViewOptions.allowsAirPlayForMediaPlayback,
IOSInAppWebViewOptions.allowsPictureInPictureMediaPlayback, IOSInAppWebViewOptions.isFraudulentWebsiteWarningEnabled,
IOSInAppWebViewOptions.allowsInlineMediaPlayback, IOSInAppWebViewOptions.suppressesIncrementalRendering, IOSInAppWebViewOptions.selectionGranularity,
IOSInAppWebViewOptions.ignoresViewportScaleLimits, IOSInAppWebViewOptions.limitsNavigationsToAppBoundDomains,
will have no effect due to a WKWebView
limitation when creating the new window WebView: it's impossible to return the new WKWebView
with a different WKWebViewConfiguration
instance (see https://developer.apple.com/documentation/webkit/wkuidelegate/1536907-webview).
So, these options will be inherited from the caller WebView.
Also, note that calling InAppWebViewController.setOptions method using the controller of the new created WebView,
it will update also the WebView options of the caller WebView.
Official Android API: https://developer.android.com/reference/android/webkit/WebChromeClient#onCreateWindow(android.webkit.WebView,%20boolean,%20boolean,%20android.os.Message)
Official iOS API: https://developer.apple.com/documentation/webkit/wkuidelegate/1536907-webview
Implementation
@override
final Future<bool?> Function(InAppWebViewController controller,
CreateWindowAction createWindowAction)? onCreateWindow;