美文网首页
解决安卓系统内location.replace失效问题

解决安卓系统内location.replace失效问题

作者: 小枫学幽默 | 来源:发表于2020-05-25 15:42 被阅读0次

背景:

安卓系统webview中,若我在A页面通过 location.href = "bUrl",然后在B页面通过location.replace(cUrl)跳转到C页面,按照正常的逻辑,若我在C页面点击webview左上角的返回按钮,会直接从 C => A , 但是实践中发现,webview会先返回 B 再点返回按钮才可以返回A

解决

使用以下方式跳转即可解决

function locationReplace(url){
  if(history.replaceState){
    history.replaceState(null, document.title, url);
    history.go(0);
  }else{
    location.replace(url);
  }
}

相关文章

网友评论

      本文标题:解决安卓系统内location.replace失效问题

      本文链接:https://www.haomeiwen.com/subject/rqvyahtx.html