Reputation: 53
I have a web view at the bottom of one of my view controllers that contains links. What I want to do is that when the user clicks on one of the links in the web view it opens a web view that takes up the screen with the with the content of the page the user has clicked on. Or maybe when the user clicks on one of the links in the web view, the user is taken to safari to display the content of the link. Anyone know how to do this? Cheers.
Above is a screen shot of the web view with the links that the user can click on..
Upvotes: 0
Views: 40
Reputation: 531
Try this:
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
{
NSURL *requestURL =[ request URL ];
if ( ( [ [ requestURL scheme ] isEqualToString: @"http" ] || [ [ requestURL scheme ] isEqualToString: @"https" ] || [ [ requestURL scheme ] isEqualToString: @"mailto" ])
&& ( navigationType == UIWebViewNavigationTypeLinkClicked ) )
{
return ![ [ UIApplication sharedApplication ] openURL: requestURL] ;
}
return YES;
}
Upvotes: 1
Reputation: 546
You can use delegate - webView:shouldStartLoadWithRequest:navigationType:
of UIWebView. Before loading each url it will call following delegate -
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
you will able to get request url from request and push new view controller.
Upvotes: 2