【问题标题】:Stop iframe redirect/opening mobile safari in phonegap project在 phonegap 项目中停止 iframe 重定向/打开移动 Safari
【发布时间】:2012-06-30 02:46:05
【问题描述】:

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

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

有没有办法停止重新加载? 抛开刮刮的道德:-)

【问题讨论】:

    标签: iphone ios iframe cordova


    【解决方案1】:

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

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

    如果您不使用 Build,请在您的 Cordova.plist/Phongap.plist 中设置此项:

    OpenAllWhitelistURLsInWebView = 'Yes'
    

    【讨论】:

    • 我不是通过 PG 构建来构建的。我可以做这个选项吗?
    • 是的,我正在寻找语法。
    • 谢谢@ThinkingStiff 我没有那个选项,但我认为这是因为我在相当稳定的 PG 1.4.1 上。我可能不得不在某个时候转移到 Cordova
    • @AdamWare 我正在使用 PhoneGap 1.8.1。
    【解决方案2】:

    我在这篇文章中找到了答案 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"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-21
      • 2014-12-08
      • 2017-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多