1 history对象
例如:新建4个页面,分别是:
<h1>这里是1.html</h1> <a href="2.html">点这里跳转到2.html</a>
<h1>这里是2.html</h1> <a href="3.html">点这里跳转到3.html</a>
<h1>这里是3.html</h1> <a href="4.html">点这里跳转到4.html</a>
<body>
<h1>这里是4.html</h1>
</body>
<script type="text/javascript">
// history 历史记录
// 访问浏览器页面的历史记录都可以在history里面得到
// alert(history.length);
setTimeout(function(){
// 返回上一个访问记录(返回上一页)
// history.back();
// 这里(-1)就是返回上一个页面,(-2)就是返回前2个页面
history.go(-1);
},2000);
</script>
2 location对象
<body>
<h1>网页没找到,3秒钟后跳到优酷网首页</h1>
</body>
<script type="text/javascript">
// 设置一个定时炸弹3秒钟执行
setTimeout(function(){
// 三秒钟跳转到优酷网 location 定位; 位置### replace 代替; 替换;
// 这个跳转后不能返回去
// location.replace('http://youku.com');
// replace和assign都是跳转,只有一点点区别,一个能返回,另一个不能
// 这个跳转后有历史记录能退回去(返回);
location.assign('http://youku.com');
// 还有一个跳转是
location.href ='http://youku.com';
},3000);
</script>
3、重新加载页面
<script type="text/javascript">
// 设置一个随机小数
document.write(Math.random());
// 定时炸弹,每隔一秒刷新一次网页;
setTimeout(function(){
// reload 重装,重新加载 刷新页面 自动刷新页面 这个可以不断刷新的原因是:进到刷新一次页面原来的就取消了重新来过,再进到这个页面,又自动的刷一次,不断的刷
location.reload();
},1000)
</script>
原文链接:https://www.qiquanji.com/post/7698.html
本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。
微信扫码关注
更新实时通知