Reputation: 156
I'm trying to display a page, for example, www.google.com, in a PhoneGap application. However, I can't get the page to open in Safari, much less within PhoneGap (which is my ultimate goal).
I saw this post: PhoneGap for iPhone: problem loading external URL, and have tried from it the following:
-As described in the solution to that question, I have modified my AppDelegate.m file.
-After doing this, in part of the index.html file (created by PhoneGap), I have this code:
window.location("http://google.com");
Although the project compiles and builds fine, I see only a blank page.
I would appreciate any help, thank you.
Upvotes: 0
Views: 3072
Reputation: 2916
What you need is this charmer in your MainViewController.m It works for me in cordova 1.7.0 cordova 1.9.0 and cordova 2.1.0
- (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 ];
}
}
Upvotes: 0
Reputation: 3803
Use .href and check this post for more information about PhoneGap and external URL: PhoneGap for iPhone: problem loading external URL
Upvotes: 0
Reputation: 180004
window.location("http://google.com");
isn't valid JavaScript. You need:
window.location.replace("http://google.com");
or
window.location.href="http://google.com";
Upvotes: 2