views:

70

answers:

1

Hi there,

I'm curious if there's a way to detect a change of the displayed website inside a UIWebView. In an app I'm working on we're using a UIWebView to present a part of the functionality which are basically a few steps the user needs to follow. However, the will be a specific page at the end of these steps that I need to identify and after which the app needs to display a different view.

Unfortunately the UIWebViewDelegate doesn't seem to do the trick.

Any tips on that?

Have a nice weekend and thanks
–f

+1  A: 

If the user steps are separated on different pages, and the UIWebView needs to load the different steps, this should indeed be possible with the delegate methods.

In this example, we say that the user goes through 3 steps, named step1.htm, step2.htm and finally step3.htm. This code will detect when the user reaches the third and final step.

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    NSString *URLString = [[request URL] absoluteString];
    if ([URLString isEqualToString:@"http://www.example.com/step3.htm"]) {
        // The user reached step 3!
    }
    return YES;
}

Note that using the absoluteString method might not be the best way to find out where the user is browsing. Take a look at query, path, parameterString, etc...

alleus
Oh somehow I missed that. Thanks, that's exactly what I've been looking for!
flohei