在phonegap项目中停止iframe重定向/打开移动版Safari

Ada*_*are 5 iphone iframe ios cordova

目前我一直在将一个页面加载到我的phonegap项目中的隐藏iframe中,作为一种从我在我的应用程序中使用的移动版网站上抓取数据的方法.

问题是一个特定的网站有某种类型的帧破坏者,并发送一个重定向,退出应用程序并加载移动野生动物园的页面.

有没有办法阻止重装?抛弃刮擦的道德规范:-)

Thi*_*iff 17

如果您正在使用PhoneGap Build,请将其添加到您的config.xml文件中:

<preference name="stay-in-webview" value="true" />
Run Code Online (Sandbox Code Playgroud)

如果你没有使用Build,请在你的Cordova.plist/Phongap.plist:

OpenAllWhitelistURLsInWebView = 'Yes'
Run Code Online (Sandbox Code Playgroud)


Ada*_*are 1

我在这篇文章中找到了答案 http://craigpfau.com/2012/02/phonegap-ios-uiwebview-and-safari-app-links/

在 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];
   }
}
Run Code Online (Sandbox Code Playgroud)

您不想在 UIwebview 中打开的任何链接都可以使用 target="_blank"