Search code examples
androidhtmlandroid-webviewfragmenthref

Android WebView: shouldOverrideUrlLoading not called when user taps on local fragment identifier


In my Android app I am using shouldOverrideUrlLoading to intercept when the user taps on a link inside a local HTML page displayed in a WebView. I need to handle all cases, even when the link is to a local fragment identifier in the page, like href="samepage.html#fragment". But I see that in this case shouldOverrideUrlLoading is not called. How could I handle this case?


Solution

  • If you can modify the content it would be best to use window.onhashchange in your JavaScript. If needed you could use addJavaScriptInterface to "talk back" to your Java code.