在js中实现页面定时跳转我们要使用setInterval或setTimeOut函数,还可以使用页面的meta实现。
例1:
<script type="text/javascript" language="JavaScript">
    var startTime = new Date();
    var endTime=startTime.getTime()+10*60*1000;
    var g_blinkswitch = 0;
    var g_blinktitle = document.title;
    function getRemainTime(){
        var nowTime = new Date();
        var nMS =endTime - nowTime.getTime();
        var nM=Math.floor(nMS/(1000*60)) % 60;
        var nS=Math.floor(nMS/1000) % 60;
        if(nM==0&&nS==0&&nMS<1000) //当倒计时结束
        {
            window.focus();
            setInterval("blinkNewMsg()", 1000);
            window.location.reload();
        }
        if(nS < 10) nS = "0" + nS;
        if(nMS >= 0){
            document.getElementById("remainTime").innerHTML= nM + "分" + nS + "秒";
            setTimeout("getRemainTime()",1000);
        }       
    }   
    function blinkNewMsg()
    {
        document.title = g_blinkswitch % 2==0 ? "【   】 - " + g_blinktitle : "【新消息】 - " +
        g_blinktitle;
        g_blinkswitch++;
    }   
 window.onload=getRemainTime;
</script>
<strong id="remainTime">10分00秒</strong>
 
例2
倒计时跳转页面
<title>JS倒计时网页自动跳转代码</title>  
<script language="JavaScript" type="text/javascript">
 function delayURL(url) {
  var delay = document.getElementById("time").innerHTML;
  if(delay > 0) {
   delay--;
   document.getElementById("time").innerHTML = delay;
  } else {
   window.top.location.href = url;
  }
  setTimeout("delayURL('" + url + "')", 1000);
 }
</script>
<span id="time" style="background: #00BFFF">3</span>秒钟后自动跳转,如果不跳转,请点击下面的链接<a href="http://www.jbxue.com">脚本学堂</a>
<script type="text/javascript">
delayURL("http://www.jbxue.com");
</script>
 
例3 防刷新的倒计时代码
<!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=gb2312" /> 
<title> www.jbxue.com--倒计时页面</title> 
</head> 
<body> 
<SCRIPT LANGUAGE="JavaScript"> 
<!-- 
var maxtime; 
if(window.name==''){  
maxtime = 1*60; 
}else{ 
maxtime = window.name; 

function CountDown(){ 
if(maxtime>=0){ 
minutes = Math.floor(maxtime/60); 
seconds = Math.floor(maxtime%60); 
msg = "距离考试结束还有"+minutes+"分"+seconds+"秒"; 
document.all["timer"].innerHTML = msg; 
if(maxtime == 5*60) alert('注意,还有5分钟!'); 
--maxtime; 
window.name = maxtime;  

else{ 
clearInterval(timer); 
alert("考试时间到,结束!"); 


timer = setInterval("CountDown()",1000); 
//-->
</SCRIPT> 
<div id="timer" style="color:red"></div>  
</body> 
</html>

Javascript倒计时页面跳转的更多相关文章

  1. JavaScript 之 页面跳转及Frame动态加载

    一.页面跳转 JS跳转大概有以下五种方式: 1.跳转到B页面 <script language="javascript" type="text/javascript ...

  2. javascript实现页面跳转

    这里指的页面跳转是将浏览器标签页转到新的网址. 只需要使用 window.location.href="url" 就行了 示例 <!DOCTYPE html> < ...

  3. Javascript实现页面跳转的几种方式

    概述 相信很多Web开发者都知道,在开发Web程序的时候,对于页面之间的跳转,有很多种,但是有效的跳转则事半功倍,下面就是我在平时的开发过程中所用到的一些JavaScript跳转方式,拿出和大家共享一 ...

  4. JavaScript 各种页面跳转方法

    第一种: window.location.href="login.jsp?backurl=\"+window.location.href; 第二种: alert("返回& ...

  5. js倒计时页面跳转

    HTML: <p><span id="timer">60</span>s 后跳转到百度首页</p> JS: //倒计时方法 func ...

  6. 《JavaScript》页面跳转

    window.location.href: <i onclick="window.location.href = '/Form/Form_Write/Index?viewname=Fo ...

  7. JS页面跳转的常用方法整理.

    <script type="text/javascript"> //js页面跳转 function showtabs() { window.location.href ...

  8. 通过javascript库JQuery实现页面跳转功能代码

    通过javascript库JQuery实现页面跳转功能代码的四段代码实例如下. 实例1: 1 2 3 4 $(function(){ var pn = $("#gotopagenum&quo ...

  9. javascript倒计时调转页面

    <html><head><meta http-equiv="Content-Type" content="text/html; charse ...

随机推荐

  1. C#_自动化测试 (四) 自动卸载软件

    在平常的测试工作中,经常要安装软件,卸载软件,  即繁琐又累.  安装和卸载完全可以做成自动化. 安装软件我们可以通过自动化框架,自动点击Next,来自动安装.  卸载软件我们可以通过msiexec命 ...

  2. linux下使用find xargs grep查找文件及文件内容

    1,在某个路径下查文件. 在/etc下查找“*.log”的文件 find /etc -name “*.log” 2,扩展,列出某个路径下所有文件,包括子目录. find /etc -name “*” ...

  3. 如何在linux下解压缩rar和zip格式的文件压缩包

    转载:http://oldboy.blog.51cto.com/2561410/597515 使用apt-get安装:  sudo apt-get install  rar  zip rar使用: 将 ...

  4. 如何优雅的实现界面跳转 之 统跳协议 - DarwinNativeRouter

    PS 感谢大家的关注,由于我本想开源4个库,除了router, 另外三个分别是native dispatcher, web dispatcher 和 react dispatcher , 所以rout ...

  5. Starship Troopers

    Problem Description You, the leader of Starship Troopers, are sent to destroy a base of the bugs. Th ...

  6. C - Minimum Inversion Number

    Description The inversion number of a given number sequence a1, a2, ..., an is the number of pairs ( ...

  7. android 读取串口数据的服务

    2016-09-1813:10:03 继承Service,定义抽象方法onDataReceived,子类通过实现抽象方法获取接收到数据的回调. package com.zrsoft.liftad.se ...

  8. 使用copy再次实现Circle类,保证不能有内存泄漏问题

    #import <Foundation/Foundation.h> //xieyi @protocol showOn @required -(void)printOn; @end // l ...

  9. .NE 学习概要

    也是个人的学习计划,仅供参考:)

  10. 减小iOS应用程序的大小

    减小iOS应用程序的大小 本文译自:Reducing the size of my App Q: 怎样才能让我的程序安装包小一点,让程序的下载和安装更快速? A: 本文收集了一些减小程序安装包大小的相 ...