添加和修改历史条目
history新特性pushState、replaceState
具体的API:https://developer.mozilla.org/en-US/docs/Web/API/History_API
别人的理解:https://www.cnblogs.com/mickybg/p/6527552.html
自己的运用:
<script>
window.onload=function(){
//获取URL?后面的参数
var url = document.location.toString();
var arrUrl = url.split("?");
//增加时间戳
var myTime =new Date().getTime();
//判断URL?是否有参数
if(arrUrl[1] == undefined){
history.replaceState({page: 1}, '', '?lp='+ myTime);
}else{
//URL后有参数
var lp = arrUrl[1].indexOf("lp");
var newUrl = arrUrl[1].substring(0,lp-1);
//判断只有lp参数,还是有其他的参数,防止lp再加lp
if( arrUrl[1][lp-1] != undefined){
history.replaceState({page: 1}, '', '?'+newUrl+'&lp='+ myTime);
}else{
history.replaceState({page: 1}, '', '?'+newUrl+'lp='+ myTime);
}
}
}
</script>