开发者

PhoneGap loading external page instead of index.html

开发者 https://www.devze.com 2023-03-31 21:23 出处:网络
I am trying to load an external site instead of the internal index.html file found in the www folder in PhoneGap.. But have not been sucessful. I\'ve tried several things that I found online but they

I am trying to load an external site instead of the internal index.html file found in the www folder in PhoneGap.. But have not been sucessful. I've tried several things that I found online but they all address just loading external links within the wrapper instead of safari.

Which is not what I am looking for.开发者_StackOverflow社区.. I am looking for when the phonegap application loads that it loads a page hosted on my web server instead of the index.html file.


You can load external URLs in the webview. Make sure to set

super.setBooleanProperty("loadInWebView", true);

in your onCreate() method of your main class (which extends DroidGap) and then you can load external URLs.


In iOS, you need to modify the shouldStartLoadWithRequest method in your AppDelegate.m file :

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

Then, you can have change you local index.html in the www folder with :

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

Of course, this is for debugging only. You should not submit it to the AppStore, it's prohibited and it will be rejected.


Fairly certain this is by design. Most of the application stores require approval of applications. If you dynamically load your application they can't control it.

Example discussion of this on the mailing list

0

精彩评论

暂无评论...
验证码 换一张
取 消