页面跳转的两种实现方法
Posted Jener_Yan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了页面跳转的两种实现方法相关的知识,希望对你有一定的参考价值。
★利用<meta>实现
参考代码
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metahttp-equiv="refresh"content="10;url=http://www.baidu.com">
<!--http-equiv实现页面与http挂钩,content内容设置延时的时间和要跳转的目的链接地址-->
<title>javascriptDialog</title>
</head>
<bodystyle="text-align: center;">
<h2>meta实现页面跳转</h2>
<hr/>
<span>实现代码</span>
<mark><meta http-equiv="refresh" content="10;url=http://www.baidu.com"></mark>
<script>
</script>
</body>
</html>
![](https://image.cha138.com/20210611/a3ea14fed8c64aa09e97414fa8eebbdb.jpg)
★利用定时器实现
参考代码
<h2>定时器实现页面跳转</h2>
<small>结合location的replace方法实现不能返回的跳转</small>
<hr/>
<b>
<mark>10秒后跳转到百度首页</mark>
</b>
<br/>
<timeid="ShowTime"></time>
<script>
setTimeout("window.location.replace(\'http://www.baidu.com\')",10000);
//注意此处使用replace方法,因此当跳转到目的链接之后是通过浏览历史或者前进、后退按钮返回
//此处直接写执行的代码,因此需要用冒号括起来
//*延时10s后跳转到baidu
setInterval(function test(){
var time = document.getElementById(\'ShowTime\');
time.innerText =newDate().toLocaleTimeString();
},1000);
//显示当前时间
//执行代码写成函数,无需用冒号括起来,并且更规范些
</script>
![](https://image.cha138.com/20210611/e6d5ac0dd92b411fb2b59f5960d9a715.jpg)
以上是关于页面跳转的两种实现方法的主要内容,如果未能解决你的问题,请参考以下文章