原页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>点击页面</title>
</head>
<body>
<a href="./2.无效页面返回(无效页).html">点我前往</a>
</body>
</html>
无效页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
无效页面,<span>5</span>秒后返回
</body>
<script>
let span = document.querySelector('span');
let i =5;
let timer = setInterval(()=>{
i--
span.innerHTML=i
if(i<0){
// 返回上一页
history.back();
// 清空定时器
clearInterval(timer)
}
},1000)
</script>
</html>