Why is 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:
- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
{
if (!navigationAction.targetFrame.isMainFrame) {
[webView loadRequest:navigationAction.request];
}
return nil;
}
PhoneGap: Opening external URL's in Safari
Had the same problem after upgrading to Cordova 1.6.1.
Try adding target="_blank"
to your links.
That did the trick for me.
How to open Safari with Cordova 3.5 on iOS 7.1?
I finally found a way to do it by adding this to the implementation of MainViewController
in MainViewController.m
, thanks to this thread.
- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
NSString *str = url.absoluteString;
NSRange range = [str rangeOfString:@"http://"];
NSRange range1 = [str rangeOfString:@"https://"];
if (range.location != NSNotFound || range1.location != NSNotFound) {
[[UIApplication sharedApplication] openURL:url];
return NO;
}else {
return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
}
}
Related Topics
How to Change the Size of Uiactivityindicator
Uitextview Starts at Bottom or Middle of the Text
"Could Not Find Any Information for Class Named Viewcontroller"
Should I Git Ignore Xcodeproject/Project.Pbxproj File
Disabled Uibutton Not Faded or Grey
How to Apply a Tintcolor to a Uiimage
Nsattributedstring Inserting a Bullet Point
Behavior Differences Between Performblock: and Performblockandwait:
Error Appstore Connect:Missing Purpose String in Info.Plist File
Uipopovercontroller Dealloc Reached While Popover Is Still Visible
Multiline Uilabel with Adjustsfontsizetofitwidth
Our App Crashed in iOS 9 Which Upload by Xcode 10
How to Check If iOS App Is in Background
Left-Align Image and Center Text on Uibutton
How to Disable Calayer Implicit Animations
Add Segmented Control to Navigation Bar and Keep Title with Buttons