9

您好,我正在尝试使用 PhoneGap 为 iPad 开发应用程序。我想在 index.html 页面中动态加载外部网站的主页。不幸的是使用

window.location.href = "http://mywebsite.com/cgi-bin/index.py"

触发 Safari 窗口的打开,而不是使用 PhoneGap 容器。

有什么建议么?

非常感谢

克劳斯

4

2 回答 2

5

有一个更简单的选择:修改 config.xml

在 WebView 中打开所有链接

停留在 webview 中,值为 true 或 false

  • 例子:<preference name="stay-in-webview" value="true" />

  • 如果设置为 true,所有链接(即使目标设置为空白)都将在应用程序的 webview 中打开

  • 仅当您希望服务器中的页面接管整个应用程序时才使用此首选项

  • 默认为假

来源:https ://build.phonegap.com/docs/config-xml

于 2012-09-08T20:54:51.240 回答
3

在项目的'Classes'部分找到AppDelegate.m文件,找到webView:shouldStartLoadWithRequest:navigationType 让函数看起来像这样,再试一次!

- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL *url = [request URL];
    if ([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) {
        [[UIApplication sharedApplication] openURL:url];    
        return NO;
    }
    else {
       return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
    }
}
于 2011-10-17T23:50:58.033 回答