直接上代码
var Url=window.location.href;
function timestamp(url){
// var getTimestamp=Math.random();
var getTimestamp=new Date().getTime();
if(url.indexOf("?")>-1){
url=url.substr(0,url.indexOf("?"))+"?timestamp="+getTimestamp
}else{
url=url+"?timestamp="+getTimestamp
}
return url;
}
//网页URL添加时间戳
//window.history.pushState 不刷新页面,但是改变页面的url地址
window.history.pushState({},0,timestamp(Url));
console.log(window.location.href);
本文介绍了一种在网页URL中动态添加时间戳的方法,通过使用JavaScript,可以在不刷新页面的情况下,利用history.pushState更新URL,加入时间戳参数,有效避免浏览器缓存问题。
856

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



