Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable hyperlinks in UIWebView

I want to disable hyperlinks in UIWebVIew after the initial page loaded without disabling the scrolling feature. That is, I should have user interaction enabled.

like image 588
Robert Childan Avatar asked May 10 '26 17:05

Robert Childan


1 Answers

You can work with webView shouldStartLoadWithRequest like this:

    (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
    {

            NSURL *loadURL = [[request URL]retain];
            //change next line to whatever condition you need, e.g.
            //[[loadURL relativeString]  ....] contains a certain substring 
            //or starts with certain letter or ...
            if([[loadURL scheme] isEqualToString: @"file"])
            {
               [loadURL release]; 
            return TRUE;
            }
            [loadURL release];
            return FALSE;
    }

You also have to set the webViews delegate an object of class where this method is implemented in: [webView setDelegate:my...];

By the implementation above, no url is loaded except those for which the condition is true. At least for the url of the first site it has to be true. The code above works for a web view initially loaded with contents of a file, containing only links to 'http://' or 'https://' or ...

like image 163
Kai Huppmann Avatar answered May 12 '26 06:05

Kai Huppmann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!