0

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

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

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

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

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

尽管该项目可以正常编译和构建,但我只看到一个空白页。

我会很感激任何帮助,谢谢。

4

3 回答 3

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

不是有效的 JavaScript。你需要:

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

或者

window.location.href="http://google.com";
于 2012-01-10T19:22:48.273 回答
0

您需要的是 MainViewController.m 中的这个迷人者 它在科尔多瓦 1.7.0 科尔多瓦 1.9.0 和科尔多瓦 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 ];
}
    }
于 2012-11-05T08:47:26.053 回答
0

使用 .href 并查看此帖子以获取有关 PhoneGap 和外部 URL 的更多信息:PhoneGap for iPhone:加载外部 URL 时出现问题

于 2012-01-10T19:27:34.540 回答