Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop iframe redirect/opening mobile safari in phonegap project

Currently I have been loading a page into a hidden iframe within my phonegap project as a way of scraping data off a mobile version of a website I use within my app.

The problem is that one particular site has some type of frame buster and sends a redirect which exits the app and loads the page in mobile safari.

Is there a way to stop the reload ? Leaving the ethics of scraping aside :-)

like image 945
Adam Ware Avatar asked Jun 30 '12 02:06

Adam Ware


2 Answers

If you're using PhoneGap Build, add this to your config.xml file:

<preference name="stay-in-webview" value="true" />

If you're not using Build set this in your Cordova.plist/Phongap.plist:

OpenAllWhitelistURLsInWebView = 'Yes'
like image 132
ThinkingStiff Avatar answered Sep 28 '22 10:09

ThinkingStiff


I found an answer in this post http://craigpfau.com/2012/02/phonegap-ios-uiwebview-and-safari-app-links/

Replace this in the AppDelegate.m

- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest: (NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
   NSURL *url = [request URL];

   if ([[url absoluteString] rangeOfString:@"URLToOpenInUIWebView.com"].location != NSNotFound) {
      return YES;
   }
   else {
      return [self.viewController webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
   }
}

Any links you don't want to open in UIwebview you use target="_blank"

like image 28
Adam Ware Avatar answered Sep 28 '22 11:09

Adam Ware