1

I want that when the user clicks the back button, it will go back to the page where it clicked the link. However, in many cases, after you click a link, the website takes you through many background redirects to ads and from page to page until they get you to your destination. In such case when you click the back button, you return to an ad, or to a redirect page.

shouldOverrideUrlLoading

does not provide a solution since it includes all the redirects (webview history is just the same BTW). I tried a combination of

setOnTouchListener and WebView.HitTestResult

to detect whether the page loading is following a link click or an auto redirect but it makes many fault results.

Bottom line, I want to identify all link clicks that open a new page, so I can track the user activity and take the user back on back clicked as necessary.

How to detect whether a page is loaded after a link was actually clicked by the user or just as a loading procedure of the website?

Thanks!

ofermc
  • 287
  • 3
  • 10
  • I dont think you can do anything about this, since all pages are equal to the webviev, even a redirect page with ads... – Jonas Czech Feb 14 '15 at 17:39
  • Well... it's not that I'm trying to be Google, but Chrome knows how to navigate you well across history and to skip ads and redirects, at least according to my experience, and I wonder how it does that... – ofermc Feb 14 '15 at 17:46
  • 1
    See [here](http://stackoverflow.com/questions/16784685/webview-back-history-without-redirects) .You could probably use HitTestResult and maintain your own back history list also. See [here](http://stackoverflow.com/a/5908125/4428462) – Jonas Czech Feb 14 '15 at 17:55
  • HitTestResult had once the type ANCHOR_TYPE that would suggest a link click but that was deprecated and so current types give many fault results. Back history includes redirects and ads, so it doesn't help either. The solution of comparing URLs on shouldOverrideUrlLoading is what I'm using myself, but I suspect it is not professional enough as in many cases the website will take you to URLs that (textually speaking) are different than those you clicked on. If no good solution will be found here, this is what I'll use though. Thanks anyway. – ofermc Feb 14 '15 at 18:16
  • There probably is no better way :-) . Use `SRC_ANCHOR_TYPE` instead. – Jonas Czech Feb 15 '15 at 15:26

0 Answers0