2012-01-10 108 views
0

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

我看到这个帖子:PhoneGap for iPhone: problem loading external URL,并从它曾尝试以下操作:在解决这一问题描述

-As,我已经修改了我的AppDelegate.m文件。

- 后这样做,在的index.html文件(通过PhoneGap的创建)的一部分,我有这样的代码:

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

虽然该项目编译和构建精细,我只是一个空白见页。

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

回答

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

无效JavaScript。您需要:

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

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

哎呀!谢谢 – Objc55 2012-01-10 19:27:53

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 ]; 
} 
    }