PhoneGap: Can't Load External Website

3k views Asked by At

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.

3

There are 3 answers

0
ceejayoz On BEST ANSWER
window.location("http://google.com");

isn't valid JavaScript. You need:

window.location.replace("http://google.com");

or

window.location.href="http://google.com";
0
AAV On

Use .href and check this post for more information about PhoneGap and external URL: PhoneGap for iPhone: problem loading external URL

0
iOSAndroidWindowsMobileAppsDev On

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 ];
}
    }