views:

190

answers:

1

Is there a way to capture clicks on links within a UIWebView. I want to find out the address that the user has clicked, but not actually go to the page.

Is this possible?

+2  A: 

Yes there is a delegate method you're view controller can implement:

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

reference:

http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIWebViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIWebViewDelegate/webView:shouldStartLoadWithRequest:navigationType:

Corey Floyd
thanks. for future reference, you also have to put this within the method, otherwise it counts load requests which are not clicks: if (navigationType == UIWebViewNavigationTypeLinkClicked) { /*do something with url*/ }
cannyboy