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 InAppWebViewSettings.javaScriptCanOpenWindowsAutomatically setting to true
.
NOTE for Android: you need to set InAppWebViewSettings.supportMultipleWindows setting to true
.
Also, if the request has been created using JavaScript (window.open()
), then there are some limitation: check the NavigationAction class.
NOTE for iOS and MacOS: setting these initial options: InAppWebViewSettings.supportZoom, InAppWebViewSettings.useOnLoadResource, InAppWebViewSettings.useShouldInterceptAjaxRequest,
InAppWebViewSettings.useShouldInterceptFetchRequest, InAppWebViewSettings.applicationNameForUserAgent, InAppWebViewSettings.javaScriptCanOpenWindowsAutomatically,
InAppWebViewSettings.javaScriptEnabled, InAppWebViewSettings.minimumFontSize, InAppWebViewSettings.preferredContentMode, InAppWebViewSettings.incognito,
InAppWebViewSettings.cacheEnabled, InAppWebViewSettings.mediaPlaybackRequiresUserGesture,
InAppWebViewSettings.resourceCustomSchemes, InAppWebViewSettings.sharedCookiesEnabled,
InAppWebViewSettings.enableViewportScale, InAppWebViewSettings.allowsAirPlayForMediaPlayback,
InAppWebViewSettings.allowsPictureInPictureMediaPlayback, InAppWebViewSettings.isFraudulentWebsiteWarningEnabled,
InAppWebViewSettings.allowsInlineMediaPlayback, InAppWebViewSettings.suppressesIncrementalRendering, InAppWebViewSettings.selectionGranularity,
InAppWebViewSettings.ignoresViewportScaleLimits, InAppWebViewSettings.limitsNavigationsToAppBoundDomains,
InAppWebViewSettings.upgradeKnownHostsToHTTPS,
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.setSettings method using the controller of the new created WebView,
it will update also the WebView options of the caller WebView.
NOTE for Web: this event will be called only if the iframe has the same origin. It works only for window.open()
javascript calls.
Also, there is no way to block the opening the window in a synchronous way, so returning true
will just close it quickly.
Officially Supported Platforms/Implementations:
- Android native WebView (Official API - WebChromeClient.onCreateWindow)
- iOS (Official API - WKUIDelegate.webView)
- MacOS (Official API - WKUIDelegate.webView)
- Web
- Windows (Official API - ICoreWebView2.add_NewWindowRequested)
Implementation
final Future<bool?> Function(
T controller, CreateWindowAction createWindowAction)? onCreateWindow;