Open Target="_Blank" Links Outside of Uiwebview in Safari

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



Leave a reply



Submit