Search code examples
iosuiwebviewuiwebviewdelegate

How to detect when UIWebView changes page?


How can I detect when a UIWebView changes a page? At the minute I am using

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

but this not only detects the page change but also each request on the page.

I am trying to get it so that when the user clicks on a link it detects the click and then I can see what the url is that the user is trying to see.

Any ideas?

Thanks


Solution

  • So, you could interrogate navigationType ... defined as ...

    enum {
       UIWebViewNavigationTypeLinkClicked,
       UIWebViewNavigationTypeFormSubmitted,
       UIWebViewNavigationTypeBackForward,
       UIWebViewNavigationTypeReload,
       UIWebViewNavigationTypeFormResubmitted,
       UIWebViewNavigationTypeOther
    };
    typedef NSUInteger UIWebViewNavigationType;
    

    ... and act accordingly, and/or look into the request for any particulars ...

        NSURL *url = [request URL]; or NSURL *url = [[request URL] absoluteString];