Loading a SPA (Single Page Application) website in Android's webview
I use the shouldoverrideurl method to monitor the URL of Webview and perform some preprocessing on the URL
However, most of the changes in SPA are hash value changes, so this method cannot monitor changes
Jump from a.html#/home
to a.html#/other
Is there any way to monitor changes in hash values?
Only available through HTML5’s newly added
window.onhashchange()
API.shouldoverrideurl
should not be monitored.If you don’t want to modify the js code, you can inject it in java:
Define a class that handles js:
Inject into webview:
Listen to onhashchange event: