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 ExternalHosts
property 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)
google.com
http://docs.phonegap.com/en/1.9.0/guide_whitelist_index.md.html#Domain%20Whitelist%20Guide
For example, check my demo application here
I have used that piece of code in MainViewController.m in cordova 1.7.0 cordova 1.9.0 and cordova 2.1.0 and it works pretty well. You just need to move that code to the correct file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.