api.Window.open - does not work on iOS
What type of issue is this?
Incorrect support data (example: BrowserX says "86" but support was added in "40")
What information was incorrect, unhelpful, or incomplete?
The table says window.open() works on iOS, but it doesn't. A google search for "ios js window.open" will find plenty of posts that agree it doesn't work.
What browsers does this problem apply to, if applicable?
Safari
What did you expect to see?
Point Safari (macOS) debugger at a webview on iOS (either in Safari-iOS or any iOS app that lets you see its WKWebViews), Execute window.open("https://apple.com") in the console.
Did you test this? If so, how?
above
Can you link to any release notes, bugs, pull requests, or MDN pages related to this?
https://developer.mozilla.org/en-US/docs/Web/API/Window/open
Do you have anything more you want to share?
No response
MDN URL
https://developer.mozilla.org/en-US/docs/Web/API/Window/open
MDN metadata
MDN page report details
- Query:
api.Window.open - Report started: 2023-12-18T17:18:54.439Z
It appears that this method doesn't work if the target is unspecified or is _blank. Using _self, _parent and _top as the target works as expected.
I have learned that _blank is handled by the webview's WKUIDelegate (if it has one). If the delegate implements webView(_:createWebViewWith:for:windowFeatures:), it will be called with navigationAction.navigationType == .other and navigationAction.request.url set.
The delegate can choose to
- ignore the attempt (returning
nil) - open the url internally to the app (returning a new
WKWebView), or - open the url in the device browser with
UIApplication.shared.open(url)
Most of the sample code I've found suggests that the delegate should return nil in the 3rd case. If it does, the result of the window.open() will be nil, indicating 'failure' to the JS side.
But the delegate can return a WKWebView, e.g. WKWebView(frame: .infinite, configuration: configuration), in which case the JS side will get a WindowProxy indicating success. It is not necessary for the app to retain or display the returned WKWebView.