起始
在 H5 的页面中我调用了如下的 JS 代码
<script>
function reLocation(){
window.location.href = "./welcome_daily.html";
}
setTimeout("reLocation()", 2000);
</script>
这在 4.4 的手机上正常运行,在一台 7.0 ,一台 8.0 的机器上却没有任何反应,并且也没有崩溃。
排错
在排除了 H5 错误的可能性之后,那么就只可能是 webView 不同版本的兼容问题了,然后我在 AS 的 log 窗口中,看到了一条 描述性的语句: Denied starting an intent without a user gesture … file:///android_asset/html/welcome_daily.html。
从上面的摘出来的日志中,我可以确定的是 JS 代码是被执行了,那么就是 webView 不知为何拦截了这次 H5 自身的跳转。
解决
最终通过 stackoverflow/google/百度 确认了问题。
Denied starting an intent without a user gesture
在此先感谢作者,正如作者文中所言
From newest androids, the WebView and Chrome Client is separated application which can be automatically updated without user intention.
From Chrome x >= 25 version, they changed how loading url is working in android application which is using webview component. https://developer.chrome.com/multidevice/android/intentsLooks like they are blocking changing url without user gesture and launched from JavaScript timers
本文介绍了一种在Android4.4以上版本中遇到的WebViewJS自动跳转被拦截的问题,并提供了具体的解决办法。
5908

被折叠的 条评论
为什么被折叠?



