• 页面闲置一段时间后,跳转


    这里提供两个用JS实现的页面闲置后跳转的例子

    <script>
    function count()
    {
        timer = window.setInterval("aa()", 1000); 
    }
    
    function resetcount()
    {
        sec=0;
    }
    var timeout=10;//设置到时时间为10秒
    var sec=0;
    function aa()
    {
        eslapetime.innerHTML=sec++;
        if (sec==timeout)
            window.location="b.asp";
    }
    </script>
    
    <body onload="count()" onmousemove=resetcount()  onkeypress=resetcount()">
    <span style="font-size:100px">停留时间:<span id="eslapetime" style="color:Red;font-size:100px"></span>秒
    </body>
    
    <body style="text-align:center" onmousemove="goindex()" onclick="goindex()" onkeypress="goindex()">
     <script> 
      var t;
      t=setTimeout('location.href="login.aspx"',1*6000);  //6秒
      function goindex()
      { 
           clearTimeout(t); 
           t=setTimeout('location.href="login.aspx"',1*6000); 
      }
     </script> 
     ..............
     </body>
    

    总结:

    其实两个例子使用的方法是一样的,都是根据JS提供的setTimeout来实现的。

    setTimeout('location.href="login.aspx"',1*6000)的含义是6秒钟之后执行location.href="login.aspx",也就是页面的跳转,注意, 此处如果是登出系统,应该对页面的session 和cookie进行清除。

    onmousemove="goindex()" onclick="goindex()" onkeypress="goindex()" 是响应键盘和鼠标的事件,并调用goindex()方法,从而初始化setTimeout,重新计算时间。

    除了JS实现的方法之外,还有其他方法可以选择,比如session 和cookie ,当然django对SESSION也提供了相关的方法

  • 相关阅读:
    异常
    带参数的方法
    变量,基本类型,数据类型和运算符
    数据类型转换(针对数字类型)
    this关键字
    面向对象DAO模式
    常见类 Object
    方法和包
    final关键字
    abstract关键字
  • 原文地址:https://www.cnblogs.com/codinggirl/p/2995382.html
Copyright © 2020-2023  润新知