开发者

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 …… an开发者_如何转开发d my action.

Thank you,

James


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜