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

时间:2012-06-30 02:46:05

标签: iphone ios iframe cordova

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

问题是,一个特定的网站有某种类型的框架破坏者,并发送一个重定向,退出应用程序并在移动游猎中加载页面。

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

2 个答案:

答案 0 :(得分:17)

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

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

如果你没有在Cordova.plist/Phongap.plist

中使用Build set
OpenAllWhitelistURLsInWebView = 'Yes'

答案 1 :(得分: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];
   }
}

您不想在UIwebview中打开的任何链接使用target =“_ blank”