Skip to content

Instantly share code, notes, and snippets.

@hsleedevelop
Last active July 21, 2020 07:21
Show Gist options
  • Save hsleedevelop/6f8c2f64dfbf75bcf169f7b7e8620523 to your computer and use it in GitHub Desktop.
Save hsleedevelop/6f8c2f64dfbf75bcf169f7b7e8620523 to your computer and use it in GitHub Desktop.
WKWebView not opening links with target=“_blank”?
//My solution is to cancel the navigation and load the request with loadRequest: again. This will be come the similar //behavior like UIWebView which always open new window in the current frame.
//
//Implement the WKUIDelegate delegate and set it to _webview.uiDelegate. Then implement:
//https://stackoverflow.com/a/25853806/3374327
- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
{
if (!navigationAction.targetFrame.isMainFrame) {
[webView loadRequest:navigationAction.request];
}
return nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment