2

I have the following method in a UIViewController:

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

My webview has two links in the view; I want to be able to distinguish between the two of them so that I know which one the user clicked on.

Does anyone know how to?

Abizern
  • 146,289
  • 39
  • 203
  • 257
jylee
  • 833
  • 2
  • 8
  • 15
  • I tried by creating a NSURLRequest that is the same as the URL as one of the links and said if [request isEqual: myURL] then do something, but they're not equal apparently. I've nslogged them both and they appear to be the same though. – jylee May 24 '11 at 13:47

1 Answers1

2

You must extract a url string from NSURLRequest:

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
    NSURL *requestUrl = [request URL];
    NSString *currentPath = [requestUrl path];
...
}

Then use currentPath to compare with your two URLs. If those URL are unknown you should parse your html file to find them in it. You cannot get access to HTML document structure through UIWebView because it is extremely complicated.