0
votes

My goal is to allow UIWebView load initial link, but disallow any further navigation.

I saw question:

Disable hyperlinks in UIWebView

So, I wired referenced webView property from interface builder.

I specified that my UIViewController uses UIWebViewDelegate:

@interface LegalViewController : UIViewController<UIWebViewDelegate>

In the code, on viewDidLoad, I do following:

 mFirstLoad = TRUE;
 webView.delegate = self;

And I have following code:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    if (!mFirstLoad)
        return FALSE;

    mFirstLoad = FALSE;
    return TRUE;
}

shouldStartLoadWithRequest is called both initial call and when I click on the link. However, even if shouldStartLoadWithRequest returns FALSE, UIWebView still proceeds and loads a new page.

I see this problem on iOS Simulator 6.0

How can I fix this behavior?

3
are you sure the delegate method is being called?mkral
Yes. I put a breakpoint in it and saw that it was hit (both for initial page load and after I click the link)Victor Ronin
If you just put return NO; for all does it still load?mkral
If I just return NO then it doesn't load initial page.Victor Ronin
I think I found the reason for the problem. I am not sure how to properly call it (not a big expert on HTML and Javascript). However the link has following code : "<a href="/something" data-transition="flip">Something</a>" As result, callback is called, but it looks like results of this callback is ignored.Victor Ronin

3 Answers

2
votes

return NO based on type to exclude links

return !(navigationTpe==UIWebViewNavigationTypeLinkClicked);

0
votes

Is it possible your boolean is getting reset somehow? What happens if you just return NO for (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType?

0
votes

Here is the same thing which I wrote in comments:

I think I found the reason for the problem. I am not sure how to properly call it (not a big expert on HTML and Javascript). However the link has following code : "<a href="/something" data-transition="flip"</a> As result, callback is called, but it looks like results of this callback is ignored.

As result most likely solution is here: Remove hyperlinks in uiwebview