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 :-)
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'
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With