location.replace 在安卓中无效的解决办法

2,020 阅读1分钟

使用location.replace时,在移动端安卓机器中发现页面并没有被replace只是,做了页面的跳转

解决办法:

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

参考文章:Android webview "location.replace" doesn't work](stackoverflow.com/questions/1…)