PhoneGap加载外部页面而不是index.html

时间:2011-08-31 17:21:24

标签: asp.net-mvc cordova

我正在尝试加载外部网站,而不是在PhoneGap的www文件夹中找到的内部index.html文件。但是还没有成功。我尝试了一些我在网上找到的东西,但它们都只是在包装器中加载外部链接而不是safari。

这不是我要找的......我正在寻找当phonegap应用程序加载它加载托管在我的Web服务器而不是index.html文件上的页面时。

4 个答案:

答案 0 :(得分:2)

您可以在网页浏览中加载外部网址。确保设置

super.setBooleanProperty("loadInWebView", true);

在主类的onCreate()方法中(扩展DroidGap),然后你可以加载外部URL。

答案 1 :(得分:0)

相当确定这是设计上的。大多数应用程序商店都需要批准应用程序。如果动态加载应用程序,则无法控制它。

Example discussion of this on the mailing list

答案 2 :(得分:0)

在iOS中,您需要修改AppDelegate.m文件中的shouldStartLoadWithRequest方法:

- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL *url = [request URL];
    if ( [ [url scheme] isEqualToString:@"http"] || [ [url scheme] 
                                                     isEqualToString:@"https"] )   
    { 
        return YES; 

    } else { 

        return [ super webView:theWebView shouldStartLoadWithRequest:request 
                navigationType:navigationType]; 
    } 
}

然后,您可以在www文件夹中更改本地index.html:

<html> 
<body onload="document.location.href='http://yourComputerIpOrServer/index.html';"> 
<h1>Loading....</h1> 
</body> 
</html> 

当然,这仅用于调试。您不应该将其提交给AppStore,它是被禁止的,它将被拒绝。

答案 3 :(得分:-1)

你也可以在iOS上使用它。看看这个链接。工作良好。 https://gist.github.com/827979

相关问题