Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.location.href javascript does not trigger shouldOverrideUrlLoading

Tags:

android

My tested on nexous one (compiled with android 2.2) shows that shouldOverrideUrlLoading is not triggered when the page is redirected via window.location.href. The onPageFinished is trigger as usual.

Could anyone advise how to intercept javascript page redirect? Any other way to redirect the page in javascript so shouldOverrideUrlLoading is triggered? Is this a bug for shouldOverrideUrlLoading?

Thanks,

June

like image 931
June Jorgensen Avatar asked Nov 14 '22 01:11

June Jorgensen


1 Answers

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.

like image 171
Tze Min Avatar answered Dec 23 '22 02:12

Tze Min