window.location.href JavaScript不触发shouldOverrideUrlLoading [英] window.location.href javascript does not trigger shouldOverrideUrlLoading

查看:1539
本文介绍了window.location.href JavaScript不触发shouldOverrideUrlLoading的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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.

这对我的作品。

这篇关于window.location.href JavaScript不触发shouldOverrideUrlLoading的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆