I am trying to link to an external link using the anchor tag like this: Google .
In order to do that, i added this code in appDelegate.m(the code is from here: https://gist.github.com/2012253):
- (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 ];
}
}
But i am not still be able to link to Google… Am i doing something wrong? Need some help.
Make sure your
ExternalHostsproperty in Cordova.plist file is properly set. ExternalHosts is an array of hosts that you are whitelisting so that it can be accessed from your application.For google (http and https)
http://docs.phonegap.com/en/1.9.0/guide_whitelist_index.md.html#Domain%20Whitelist%20Guide
For example, check my demo application here