window.location.href JavaScript不触发shouldOverrideUrlLoadinglocation、window、href、shouldOverrideUrlLoad

2023-09-05 09:29:40 作者:看我不爽就滚蛋

我在nexous一(与Android 2.2编译)显示shouldOverrideUrlLoading不会触发页面时通过window.location.href重定向测试。该onPageFinished是触发像往常一样。

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.

谁能告知如何拦截JavaScript页​​面重定向? 任何其他方式重定向页面的JavaScript,以便shouldOverrideUrlLoading被触发? 这是shouldOverrideUrlLoading一个错误?

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?

谢谢

推荐答案

在我的情况下,在使用了window.location =HTTP:// XXX在我的网页,事件 shouldOverrideUrlLoading()不会被触发。

In my case, when using window.location = "http://xxx" in my webpage, the event shouldOverrideUrlLoading() is not triggered.

不过,如果我使用自定义URL方案或协议,如 androidurl:// shouldOverrideUrlLoading()被激发。我的解决方法是要使用自定义的协议,并添加以下code。在 shouldOverrideUrlLoading()方法:

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://");
}

这将改变自定义协议回的http:// 协议,你可以处理正确的URL从那里

This will change the custom protocol back to the http:// protocol and you can handle the correct url from there.

这对我的作品。