PhoneGap:无法加载外部网站

时间:2012-01-10 19:16:49

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

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

我看过这篇文章:PhoneGap for iPhone: problem loading external URL,并尝试了以下内容:

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

- 执行此操作后,在 index.html 文件的一部分(由PhoneGap创建)中,我有以下代码:

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

虽然项目编译和构建正常,但我只看到一个空白页面。

感谢您的帮助,谢谢。

3 个答案:

答案 0 :(得分:2)

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

无效的JavaScript。你需要:

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

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

答案 1 :(得分:0)

使用.href并查看此帖子,了解有关PhoneGap和外部网址的更多信息:PhoneGap for iPhone: problem loading external URL

答案 2 :(得分:0)

你需要的是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 ];
}
    }
相关问题