Created
May 10, 2012 16:28
-
-
Save jquave/2654307 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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