pixelbitlabs
pixelbitlabs

Reputation: 1934

UIWebView History If Statement

How can I detect the last page viewed in a UIWebView? Basically I want to say, if (in an if statement) the last page viewed in the UIWebView was @"http://www.example.com" and the current UIWebView page is @"http://www.lalala.com" then …… and my action.

Thank you,

James

Upvotes: 0

Views: 1224

Answers (1)

SVD
SVD

Reputation: 4753

In the webview delegate's webViewDidFinishLoad:, get the url of the last loaded page (by examining webview's request property) and store it in some property. Then use that property in your if statement.

Edit: add a property (lets say to the UIWebView delegate class):

@property (nonatomic, retain) NSURL* lastLoadedURL;

Then add this method:

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
self.lastLoadedURL = [webView.request URL];
}

So whenever you need to check the last loaded page you'd do something like this:

if([[self.lastLoadedURL lastPathComponent] isEqualToString:@"somepage.html"]) {
//do stuff
}

or if you're not in the UIWebView delegate class, you'd need to replace self.lastLoadedURL with (delegateClassInstance).lastLoadedURL.

Upvotes: 2

Related Questions