第一种推荐:
<script>
function refresh(){
if(sessionStorage.getItem("isReload")){
console.log("页面被刷新");
}else{
console.log("首次被加载");
window.location.reload();
sessionStorage.setItem("isReload", true)
}
}
window.onload = refresh;
</script>
第二种
<script>
function refresh(){
url = location.href;
console.log(url);
var once = url.split("#");
if (once[1] != 1) {
url += "#1";
self.location.replace(url);
window.location.reload();
}
}
setTimeout('refresh()', 1000);
</script>
第三种综合一二
<script>
function refresh(){
window.location.reload();
}
function refresh2(){
if(sessionStorage.getItem("isReload")){
console.log("页面被刷新");
}else{
console.log("首次被加载");
sessionStorage.setItem("isReload", true);
setTimeout('refresh()', 100);
}
}
setTimeout('refresh2()', 10);
</script>
参考:https://www.cnblogs.com/jian-ge/p/9969554.html https://blog.csdn.net/mtgaogao/article/details/118361601
|