29er
29er

Reputation: 9005

Iframe opens in new window once wrapped in Phonegap

I have a jquery mobile app that i am wrapping in Phonegap for Iphone/Android store. I have one page that uses an iframe, which without Phonegap, works just like you would expect. However, once wrapped, the Iframe actually causes the app to open a new window/browser, and leave the app. Does anyone know if there is a solution for this ? THanks!

Upvotes: 0

Views: 3125

Answers (2)

timo
timo

Reputation: 26

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

First, open PhoneGapDelegate.m and find this code block:

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

Insert this else-if right under the first if statement of that block:

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

Also make sure [[UIApplication sharedApplication] openURL:url] is uncommented in the last else statement (otherwise clicking links in the iFrame will not work):

else
{
    //NSLog(@"Unknown URL %@", [url description]);
    [[UIApplication sharedApplication] openURL:url];
    return NO;
}

Upvotes: 1

Neograph734
Neograph734

Reputation: 1754

that is because phonegap disables external content by default, and refers to the built in browser.

You can fix this in the file /res/xml/cordova.xml

Right click -> open with text editor and then look for there lines:

<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 -->

I guess the documentation there speaks for itself. I don't know about allowing several access origins (i host all code on the same server) and point my initial file there as well. So I don''t use /assets/www anymore.

Upvotes: 0

Related Questions