【问题标题】:PhoneGap: Can't Load External WebsitePhoneGap:无法加载外部网站
【发布时间】:2012-11-05 16:47:26
【问题描述】:

我正在尝试在 PhoneGap 应用程序中显示一个页面,例如 www.google.com。但是,我无法在 Safari 中打开页面,更不用说在 PhoneGap 中打开页面(这是我的最终目标)。

我看到了这个帖子:PhoneGap for iPhone: problem loading external URL,并从中尝试了以下内容:

-如该问题的解决方案中所述,我修改了我的 AppDelegate.m 文件。

-这样做之后,在 index.html 文件(由 PhoneGap 创建)的一部分中,我有以下代码:

window.location("http://google.com");

虽然项目编译和构建都很好,但我只看到一个空白页。

如果有任何帮助,我将不胜感激,谢谢。

【问题讨论】:

    标签: iphone objective-c xcode cordova external-links


    【解决方案1】:
    window.location("http://google.com");
    

    不是有效的 JavaScript。你需要:

    window.location.replace("http://google.com");
    

    window.location.href="http://google.com";
    

    【讨论】:

      【解决方案2】:

      使用 .href 并查看此帖子以获取有关 PhoneGap 和外部 URL 的更多信息:PhoneGap for iPhone: problem loading external URL

      【讨论】:

        【解决方案3】:

        您需要的是 MainViewController.m 中的这个迷人者,它适用于我在 cordova 1.7.0 cordova 1.9.0 和 cordova 2.1.0 中

        - (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request   navigationType:(UIWebViewNavigationType)navigationType
        {
        NSURL *url = [request URL];
        
        // Intercept the external http requests and forward to Safari.app
        // Otherwise forward to the PhoneGap WebView
        if ([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) {
            [[UIApplication sharedApplication] openURL:url];
        return NO;
        }
        else {
        return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
        }
            }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2020-03-10
          • 2012-07-02
          • 1970-01-01
          • 2011-09-13
          • 1970-01-01
          • 2013-07-30
          • 1970-01-01
          相关资源
          最近更新 更多