Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to detect tap on UIWebView if it's not a link

So I would like to detect a tap on UIWebView if it is not tapping on a link. How do I do this? I know that:

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

is called every time a link is clicked. However how do I know if it's a tap on the UIWebView that is other than the link? I've been searching for the web and the closest I found is this. However that does not tell me whether the tap is on a link or not

like image 437
xonegirlz Avatar asked Mar 11 '12 20:03

xonegirlz


1 Answers

Let me walk you through to why this is impossible.

- (BOOL)webView:(UIWebView *)webview shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
  1. Even if it sounds ludicrous there will be calls to this delegate method when the user has clicked a link with a navigation type of UIWebViewNavigationTypeOther instead of UIWebViewNavigationTypeLinkClicked. This happens with some javascript based pages that are commonly found on the internet.

  2. Even if it sounds completely insane there will be calls to this delegate method with UIWebViewNavigationTypeLinkClicked multiple times when in fact the user hasn't clicked a link. Some websites do embed the content of an frame/iframe using a simulated click on a hidden button, which causes multiple calls with UIWebViewNavigationTypeLinkClicked.

    This strange way in embedding content with a simulated click is done to bypass the privacy settings of certain browsers. Google was sued for this some time ago and had to pay several millions penalty, because they used this trick to set cookies in the Safari browser even if the user has configured the browser to not accept these cookies.

So, if you solely rely on UIWebView's delegate method you 'll get clicks when there are none and none when there are clicks. Thus, in a uncontrolled environment this is impossible.

But, what exactly are you trying to do?

like image 161
Vulkan Avatar answered Oct 23 '22 18:10

Vulkan