Ios

PhoneGap Apps + Load External Url

Mon Dec 17, 2012

To enable access to whitelist domain
http://docs.phonegap.com/en/1.9.0/guide_whitelist_index.md.html

To open site in app itself
for Android

ref: Stack Over Flow

for iOS
in AppDelegate.m
Change


  - (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 
  {
    return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
  }

with

  
      - (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
      {
        NSURL *url = [request URL];
        if ([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) {
          return YES;
        }
        else {
          return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
        }
      }

ref: stack over flow

if to open site in app and open in browser
in iOS

  
    - (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(    UIWebViewNavigationType)navigationType
    {
      NSURL *url = [request URL];
      if ( ([url fragment] != NULL) && ([[url fragment] rangeOfString:@"phonegap=external"].location != NSNotFound))
      {
        if ([[UIApplication sharedApplication] canOpenURL:url]) {
            [[UIApplication sharedApplication] openURL:url];
            return NO;
        }
    }
    return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
}

and in the html href include hash #phonegap=external

ref: reference