0

In my WebView, when the user clicks on a link within the webview, where is that property? I looked at the docs and have tried things like

[webView.request.URL description]
webView.request.URL.absoluteURL or absoluteString

, and everything is blank. Thanks!

J W
  • 868
  • 1
  • 12
  • 25
  • 4
    Use the search feature: http://stackoverflow.com/questions/4679378/iphone-uiwebview-get-the-url-of-the-link-clicked – lm2s Jul 09 '12 at 21:32

3 Answers3

3

Implement delegate function like

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType 
{
    if(navigationType == UIWebViewNavigationTypeLinkClicked)
    {
        // Its following the click on some link on the loaded webpage
        NSString  *strLink = [[request URL] absoluteString]; // Clicked Link URL
    }
    return YES; // return YES if you allow the page to load else return NO  
}

Hope this helps you.

Mathew Varghese
  • 4,527
  • 2
  • 17
  • 26
0

Maybe try this:

NSString *link = [webView.request.URL absoluteString];

Hope this helps!

pasawaya
  • 11,515
  • 7
  • 53
  • 92
0

you need to catch webview delegate functions when user tap on any link

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
  NSURL *url = [request URL];
  NSString *link =   [url absoluteString];
  return YES;   
}
Manish Agrawal
  • 10,958
  • 6
  • 44
  • 76