Rajesh_Bangalore
Rajesh_Bangalore

Reputation: 609

Need to open link in safari from uiwebview?

I have stored my whole html document with escape sequence in a variable... and it contains some anchor tag.. where if that has clicked, it should open in safari, not in my app webview....

Upvotes: 4

Views: 1960

Answers (2)

user529758
user529758

Reputation:

You can use the UIWebViewDelegate protocol to achieve this:

// assuming webView is a valid UIWebView
webView.delegate = self;

- (BOOL)webView:(UIWebView *)wv shouldStartLoadWithRequest:(NSURLRequest *)rq navigationType:(UIWebViewNavigationType)nt
{
    if (nt == UIWebViewNavigationTypeLinkCkicked) {
        [[UIApplication sharedApplication] openURL:[rq URL]];
        return NO;
    }

    return YES;
}

Upvotes: 3

Nimit Parekh
Nimit Parekh

Reputation: 16864

You can use following code for that.

   -(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
        if ( inType == UIWebViewNavigationTypeLinkClicked ) {
            [[UIApplication sharedApplication] openURL:[inRequest URL]];
            return NO;
        }

        return YES;
    }

Upvotes: 4

Related Questions