打开jsp/html,三秒后自动跳转

打开jsp/html,3秒后自动跳转

打开一个页面,过几秒跳转,一般会应用在某些操作成功或者失败之后,给出提示,然后跳回到别的页面。比如你注册成功或者失败后,添加成功后者失败后。效果稍微好点儿的,会用隐藏域或者ajax在页面上直接提示并刷新,不会通过这种的页面进行跳转,效果和操作体验都要比这种几秒自动跳转要好,但是这里,我还是把这种的记录一下。

 

第一种:<script> window.setInterval("location='index.jsp'",3000); </script>  使用interval函数跳转,这里的3000是毫秒单位,也就是3秒。

 

第二种:<meta http-equiv="refresh" content="3;url=http://localhost:8080/test/index.jsp" />,这里的content=3,便是3秒的跳转。

 

第三种:<script type="text/javascript">

delayURL("index.action",3000);

function delayURL(url, time) {

     setTimeout("location.href='" + url + "'", time);

}

   </script>

 

第四种:<script type="text/javascript">

function countDown(time,url){

    $("#second").text(time);//<span>中显示的内容值

     if(url==''){

             url="/";

     }

     if(--time>0){

            setTimeout("countDown("+time+",'"+url+"')",1000);//设定超时时间

     }

     else{

         location.href=url;//跳转页面

     }

}

</script>

这种的稍微麻烦点,它的显示页面代码为:

Html代码 
  1. <div class="suc">  
  2.             <div class="title"><span >操作提示</span></div>  
  3.             <ul>  
  4.                 <li><span class="font1">${msg}</span></li>  
  5.                 <li>再过<span id="second">5</span>秒后自动跳转<script language='javascript'>countDown(5,'${session.redirectUrl}');</script></li>  
  6.             </ul>  
  7.  </div>