javascript定时函数定时跳转页面(示例)

发布时间:2020-05-30编辑:脚本学堂
在js脚本中使用定时函数,定时跳转到指定的页面,比如跳转到一个页面处理完任务,然后又回到原来的页面,很有趣也很实用的功能,有需要的朋友参考下。

需求描述:
跳转到一个页面处理完任务,然后又回到原来的页面,多用于下载网站中,可以更好地留住用户。

javascript定时函数 window.setTimeout来实现。
window.setTimeout( code,time) // code 执行的代码 time 设置的时间

完整代码:
 

复制代码 代码示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>javascript自动跳转-www.jb200.com</title>
<script type="text/javascript">
function redrect()
{
window.location = "1.html";
}
window.setTimeout(redrect,3000);// 跳转函数
</script>
</head>
<body >
<h4 style="color:#F00">这是跳转页面....</h4>
</body>
</html>