Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Override shouldStartLoadWithRequest
* Overriding in __App__Delegate.m
* if this is viable, find a nicer API and merge into PhoneGap/Callback/Cordova edge
* programmatic iframe creations open in main webview
* user interactions open in Safari
- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
BOOL superValue = [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
BOOL inIframe = ![self doesRequest:request comeFromWebView:theWebView];
BOOL fromUserInteraction = (navigationType == UIWebViewNavigationTypeLinkClicked || navigationType == UIWebViewNavigationTypeFormSubmitted);
NSURL *url = [request URL];
NSLog(@"url is %@", url);
NSLog(@"inIframe is %@", (inIframe ? @"true" : @"false"));
NSLog(@"request.mainDocumentURL = %@", [request.mainDocumentURL absoluteString]);
NSLog(@"webview.request.mainDocumentURL = %@", [theWebView.request.mainDocumentURL absoluteString]);
// if in iframe and has user interaction
if (inIframe && fromUserInteraction) {
[[UIApplication sharedApplication] openURL:url];
return NO;
// otherwise, fall back to super
return superValue;
- (BOOL)doesRequest:(NSURLRequest *)request comeFromWebView:(UIWebView *)webView
// sees if the mainDocumentURL of the request matches that of the webView
// if not, is probably from an iFrame
return ([[request.mainDocumentURL absoluteString]
compare:[webView.request.mainDocumentURL absoluteString]]
== 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.