Jquery mobile Iframe在Phonegap中包装后将在新窗口中打开

Jquery mobile Iframe在Phonegap中包装后将在新窗口中打开,jquery-mobile,cordova,Jquery Mobile,Cordova,我有一个jquery移动应用程序,我正在为Iphone/Android商店包装Phonegap。 我有一个页面使用了iframe,它没有Phonegap,就像你所期望的那样工作。 但是,一旦包装好,Iframe实际上会导致应用程序打开一个新窗口/浏览器,并离开应用程序。 有人知道有没有解决办法吗? 谢谢 首先,打开PhoneGapDelegate.m并找到以下代码块: - (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequ

我有一个jquery移动应用程序,我正在为Iphone/Android商店包装Phonegap。 我有一个页面使用了iframe,它没有Phonegap,就像你所期望的那样工作。 但是,一旦包装好,Iframe实际上会导致应用程序打开一个新窗口/浏览器,并离开应用程序。 有人知道有没有解决办法吗? 谢谢

首先,打开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;
}
另外,请确保在最后一条else语句中未注释[[UIApplication sharedApplication]openURL:url](否则,单击iFrame中的链接将不起作用):


这是因为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了。

我知道这在Android上是个问题。另外,在我们对历史处理方式进行一些内部更改之前,我不确定我们是否能够修复它。这是android中的一个bug。我自己也在寻找解决办法。。。
else
{
    //NSLog(@"Unknown URL %@", [url description]);
    [[UIApplication sharedApplication] openURL:url];
    return NO;
}
<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 -->