Skip to content Skip to sidebar Skip to footer

Phonegap/cordova Open External Link Into Safari Instead Of Full Screen Inapp

I am embedding a GoogleMap in my app. On the embedded map (which is an iFrame) I have links from google:'term of use'. When I click on the link (a customer could do that by mistake

Solution 1:

I have found a solution, this is maybe not the best one as it's only for iOs (certainly scalable to android):

I added this code in the MainViewController.m:

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

    //mustNotReroot : for the google iFrame, the adress contains "embed" ==> must not be open in safari but in the appBOOL mustNotReroot = [url.path rangeOfString:@"embed"].location != NSNotFound;

    // Intercept any external http requests and forward to Safari// Otherwise forward to the PhoneGap WebViewif (([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"])&& !mustNotReroot)
    {
         NSLog(@"Rerouting to Safari %@",url);
        [[UIApplication sharedApplication] openURL:url];
        returnNO;
    }
    else
    {
        return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
    }
}

This way any http or https will be forwarded to Safari.app. Pay attention because the iFrame is understood as an external link (as it is XSS iFrame) and so it was opened in Safari, so I did the fix by adding the check mustNotReroot. The iFrame URL is : https://www.google.com/maps/embed/v1/directions?key=MyAPI_Key&origin=Campbell&destination=Sunnyvale

As it contains embed I check if it contains embed, if yes: do not forward to Safari.

If you have a better fix like a javascript fix working on both iOS and Android feel free to share it !

Post a Comment for "Phonegap/cordova Open External Link Into Safari Instead Of Full Screen Inapp"