ok, browsing the questions I\'ve found the right way to load an external page into the phonegap view (i.e. without loosing the session or opening the device browser) as explaine
This is using PhoneGap/Cordova 2.7. Inside your external app, add a link that points to "app://index".
Inside onCreate add:
this.appView.setWebViewClient(new CordovaWebViewClient(this, this.appView) {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.equalsIgnoreCase("app://index")) {
Log.d("DEBUG", url);
loadUrl(Config.getStartUrl());
return true;
} else {
return super.shouldOverrideUrlLoading(view, url);
}
}
});
This will intercept the call and redirect the user to the configured start url.
You want to use the ChildBrowser plugin to open the external web page. Then you want to set the ChildBrowser.onLocationChange property to your own function. Then when the person navigates away from the remote page you will be notified of the location change so you can then close the ChildBrowser and navigate to a new local page. You won't even need to touch the remote html page.
So to close the browser when the user navigates away from the remote page:
cb.onLocationChange = function(loc){
console.log("location = " + loc);
if (loc != "http://example.com") {
cb.close();
}
};
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 ];
}
}