Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone UIWebView - Open new UIWebView Controller from a hyperlink

Tags:

iphone

I have an embedded website that has many links but the webview window is fairly small to allow for a larger image above the list to be zoomed in and out. I need the webview to respond to hyperlinks into a new controller view with a second embedded UIWebView if at all possible.

like image 807
user457696 Avatar asked Dec 13 '22 19:12

user457696


1 Answers

The UIWebView has a delegate wich allows you to respond to certain events, e.g. a request to load new content. Just implement the following in your delegate-class

-(bool) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    //You might need to set up a interceptLinks-Bool since you don't want to intercept the initial loading of the content
    if (self.interceptLinks) {
        NSURL *url = request.URL;
        //This launches your custom ViewController, replace it with your initialization-code
        [YourBrowserViewController openBrowserWithUrl:url];     
        return NO;
    }
    //No need to intercept the initial request to fill the WebView
    else {
        self.interceptLinks = YES;
        return YES;
    }
}
like image 136
Philipp Schlösser Avatar answered May 21 '23 16:05

Philipp Schlösser