Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable links in UIWebView?

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.

like image 801
Don Wilson Avatar asked Jan 20 '10 03:01

Don Wilson


1 Answers

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;
}
like image 126
Dave DeLong Avatar answered Oct 10 '22 16:10

Dave DeLong