25

Is it possible intercept when a user clicks a link in a UIWebView and retrieve the link?

I wish to block the UIWebView from going to the clicked link and do something else.

Thanks in advance.

Chris Wagner
  • 20,773
  • 8
  • 74
  • 95
ghiboz
  • 7,863
  • 21
  • 85
  • 131

1 Answers1

43

Yes, look at the UIWebViewDelegate Protocol Reference, specifically webView:shouldStartLoadWithRequest:navigationType:

The NSURLRequest will let you know where the link they clicked is going to direct them.

You would simply return NO on this method if you want to prevent the request from loading.

Chris Wagner
  • 20,773
  • 8
  • 74
  • 95
  • I need to retrieve the content to memory only, examine it and if it's ok then display it in UIWebView. Is that possible? – fatdragon May 03 '15 at 17:47
  • You might want to use an `NSURLConnection` to download the content do you check, and then load that from disk into a webview if I understand correctly. – Chris Wagner May 04 '15 at 23:35