Declan Conway
Declan Conway

Reputation: 53

How to open UIWebView from another UIWebView?

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.

enter image description here

Above is a screen shot of the web view with the links that the user can click on..

Upvotes: 0

Views: 40

Answers (2)

Tanuj
Tanuj

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

Shohrab
Shohrab

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.

More details : https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIWebViewDelegate_Protocol/index.html#//apple_ref/occ/intfm/UIWebViewDelegate/webView:shouldStartLoadWithRequest:navigationType:

Upvotes: 2

Related Questions