0

我有一个 jquery 移动应用程序,我将它包装在 Phonegap for Iphone/Android 商店中。我有一个使用 iframe 的页面,它没有 Phonegap,就像你期望的那样工作。然而,一旦封装,Iframe 实际上会导致应用打开一个新窗口/浏览器,然后离开应用。有谁知道是否有解决方案?谢谢!

4

2 回答 2

1

http://denrobapps.com/2010/12/phonegap-and-iframes/

首先,打开 PhoneGapDelegate.m 并找到这个代码块:

- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];

/*
 * Get Command and Options From URL
 * We are looking for URLS that match gap://<Class>.<command>/[<arguments>][?<dictionary>]
 * We have to strip off the leading slash for the options.
 */
 if ([[url scheme] isEqualToString:@"gap"]) {

    InvokedUrlCommand* iuc = [[InvokedUrlCommand newFromUrl:url] autorelease];

    // Tell the JS code that we've gotten this command, and we're ready for another
    [theWebView stringByEvaluatingJavaScriptFromString:@"PhoneGap.queue.ready = true;"];

    // Check to see if we are provided a class:method style command.
    [self execute:iuc];

     return NO;
}

/*
 * If a URL is being loaded that's a local file URL, just load it internally
 */
else if ([url isFileURL])
{
    //NSLog(@"File URL %@", [url description]);
    return YES;
}

/*
 * We don't have a PhoneGap or local file request, load it in the main Safari browser.
 */
else
{
    //NSLog(@"Unknown URL %@", [url description]);
    //[[UIApplication sharedApplication] openURL:url];
    return NO;
}

return YES;
}

在该块的第一个 if 语句下面插入这个 else-if:

else if ([[url scheme] isEqualToString:@"http"])
{
    return YES;
}

还要确保 [[UIApplication sharedApplication] openURL:url] 在最后一个 else 语句中未注释(否则单击 iFrame 中的链接将不起作用):

else
{
    //NSLog(@"Unknown URL %@", [url description]);
    [[UIApplication sharedApplication] openURL:url];
    return NO;
}
于 2012-04-18T20:23:20.377 回答
0

那是因为 phonegap 默认禁用外部内容,并引用内置浏览器。

您可以在文件 /res/xml/cordova.xml 中解决此问题

右键单击-> 使用文本编辑器打开,然后查找那里的行:

<access origin="http://127.0.0.1*"/> <!-- allow local pages -->
<!-- <access origin="https://example.com" /> allow any secure requests to example.com -->
<!-- <access origin="https://example.com" subdomains="true" /> such as above, but including subdomains, such as www -->
<!-- <access origin=".*"/> Allow all domains, suggested development use only -->

我想那里的文档不言自明。我不知道允许多个访问源(我将所有代码托管在同一台服务器上)并将我的初始文件也指向那里。所以我不再使用 /assets/www 了。

于 2012-04-19T19:59:39.437 回答