Disable links in UIWebView?

hyperlink, iphone, uiwebview

Solution

You can give the `UIWebView` a delegate and implement the `-webView:shouldStartLoadWithRequest:navigationType:` delegate method to `return NO;` (except on the initial load).

That will prevent the user from viewing anything but that single page.

To provide an example requested in the comments... Start with `allowLoad=YES` and then:

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
    return allowLoad;
}

- (void)webViewDidFinishLoad:(UIWebView*)webView {
    allowLoad = NO;
}

Problem

I am loading some content from the web into a `UIWebView`, but I'd like all links to be disabled in the `UIWebView`. Is this possible? I could parse the text, but I'm looking for something easier.

Original source