当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 基于JS实现操作成功之后自动跳转页面

基于JS实现操作成功之后自动跳转页面

2020年09月26日  | 移动技术网IT编程  | 我要评论
如图所示样子:制作一个跳转提示页面:要求:1. 如果打开该页面后,如果不做任何操作则5秒后自动跳转到一个新的地址,如百度主页。2. 如果点击“返回”按钮则返回前一个页面<!doctype htm

如图所示样子:

在这里插入图片描述

制作一个跳转提示页面:
要求:
1. 如果打开该页面后,如果不做任何操作则5秒后自动跳转到一个新的地址,如百度主页。
2. 如果点击“返回”按钮则返回前一个页面

<!doctype html>
<html>
 <head>
 <title>浏览器对象</title> 
 <meta http-equiv="content-type" content="text/html; charset=gkb"/>  
 </head>
 <body>
 <!--先编写好网页布局-->
 
 <div><h1>操作成功</h1></div>
 <div><a id ="p1">5</a>后回到主页<a href="http://www.baidu.com" rel="external nofollow" >返回</a></div>
 <script type="text/javascript"> 
 
  
  
  //获取显示秒数的元素,通过定时器来更改秒数。
   
   var num = 100;
   function downtime(){
		 document.getelementbyid('p1').innerhtml=num;
     if(num>0){
      num--;
     }else{
       window.location = "http://www.baidu.com";
     }
     settimeout("downtime()",1000);
   }
  //通过window的location和history对象来控制网页的跳转。
  downtime();
 </script> 
</body>
</html>

ps:下面看下javascript五秒自动跳转到新页面

<!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>五秒跳页五秒关闭</title>
<script type="text/javascript">
function countdown(secs,surl)
{
var jumpto=document.getelementbyid('jumpto');
jumpto.innerhtml=secs;
if(--secs>0)
{
settimeout("countdown("+secs+",'"+surl+"')",1000);//注意打点
}
else{
location.href=surl;
}
}
</script>
</head>

<body>
<span id="jumpto">5</span>秒后自动跳转到//www.jb51.net/
<script type="text/javascript">countdown(5,'//www.jb51.net');</script>
</body>
</html>

到此这篇关于基于js实现操作成功之后自动跳转页面的文章就介绍到这了,更多相关js自动跳转页面内容请搜索移动技术网以前的文章或继续浏览下面的相关文章希望大家以后多多支持移动技术网!

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网