How to make links shown in phonegaps childbrowser open in Safar?
-
28-10-2019 - |
Question
I have a phone gap app which loads an HTML 5 app in a child browser. Links which are on the pages loaded in the child browser also load in the child browser. I would like these links to open in Safari. How could i do that?
Thanks
Solution
You just need to add this in your AppDelegate.m
- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
// Intercept the external http requests and forward to Safari.app
// Otherwise forward to the PhoneGap WebView
if ([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) {
[[UIApplication sharedApplication] openURL:url];
return NO;
}
else {
return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
}
}
Hope this helps
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow