I\'m trying to open links in Safari (on an iPhone) from a PhoneGap application. I\'m using PhoneGap version 3.1.0, and use PhoneGap Build, to build the application.
For iOs, in your MainViewController.m do the following
- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
if (![url isFileURL] && navigationType == UIWebViewNavigationTypeLinkClicked)
{
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
return NO;
}
}
return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
}
EDIT: For Android, in CordovaWebViewClient.java, in shouldOverrideUrlLoading do the following:
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(/*check if not external link*) {
view.loadUrl(url);
} else {
//prepend http:// or https:// if needed
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(i);
}
return true;
}