Skip to content

Instantly share code, notes, and snippets.

@jquave
Created May 10, 2012 16:28
Show Gist options
  • Save jquave/2654307 to your computer and use it in GitHub Desktop.
Save jquave/2654307 to your computer and use it in GitHub Desktop.
// Hack to pop up link clicks in a new modal view
// Thanks to http://niw.at/articles/2009/02/06/how-to-enable-the-popup-window-on-uiwebview/en
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if(navigationType == UIWebViewNavigationTypeLinkClicked || navigationType == UIWebViewNavigationTypeFormSubmitted) {
NSURL *url = [request URL];
NSString *urlString = [url absoluteString];
NSString *urlScheme = [[[request URL] scheme] lowercaseString];
if([urlScheme hasPrefix:@"http"]) {
ModalWebView *siteView = [[ModalWebView alloc] initWithNibName:@"ModalWebView" bundle:nil];
[topViewController presentModalViewController:siteView animated:YES];
[siteView loadURL:urlString];
return NO;
}
else if([urlScheme hasPrefix:@"mailto"] || [urlScheme hasPrefix:@"tel"] || [urlScheme hasPrefix:@"mms"]) {
[[UIApplication sharedApplication] openURL:url];
return NO;
}
}
return YES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment