I have a javascript function 'gotoMainPage()'
function gotoMainPage( ) {
window.location.href = "main/main.do";
}
Now, WebViewClient's shouldOverrideUrlLoading(..)
gets called if gotoMainPage( )
is executed as a result of a 'direct user interaction', such as user clicking on this div:<div.... onclick='gotoMainPage();'/>
However, if the execution is done via setTimeout( gotoMainPage, 100 );
or via an XMLHttpRequest
callback, shouldOverrideUrlLoading(..)
is never called but the requested page is loaded into the webview.
Am I missing an obvious explanation or is this a bug?
Anyone?
In my case, when using window.location = "http://xxx" in my webpage, the event shouldOverrideUrlLoading() is not triggered.
However, if I use a custom url scheme or protocol such as "androidurl://", shouldOverrideUrlLoading() is fired. My workaround would to be use a custom protocol and add the following code in the shouldOverrideUrlLoading() method:
if (url.startsWith("androidurl://")) {
url = url.replaceAll("androidurl://", "http://");
}
This will change the custom protocol back to the "http://" protocol and you can handle the correct url from there.
This works for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With