I need to detect URL hash changes in an Android WebView but can\'t find any way to do so. shouldOverrideUrlLoading()
fires on the initial page load, but does n
It is possible.
You have to declare a Javascript Interface like this :
private class MyJSI {
public void doStuff()
{
}
}
And link your webview with the Javascript Interface like this :
webView.addJavascriptInterface(new MyJSI(), "myjsi");
Then, you have to write some javascript code when the page is loaded, to call the function doStuff on hash change.
webview.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url)
{
view.loadUrl("javascript:window.onhashchange = function() { myjsi.doStuff(); };");
}
});
I hope it helps. I have tested it, and it works.