这里提供两个用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 οnlοad="count()" οnmοusemοve=resetcount() οnkeypress=resetcount()">
<span style="font-size:100px">停留时间:<span id="eslapetime" style="color:Red;font-size:100px"></span>秒
</body>
<body style="text-align:center" οnmοusemοve="goindex()" οnclick="goindex()" οnkeypress="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进行清除。
οnmοusemοve="goindex()" οnclick="goindex()" οnkeypress="goindex()" 是响应键盘和鼠标的事件,并调用goindex()方法,从而初始化setTimeout,重新计算时间。
除了JS实现的方法之外,还有其他方法可以选择,比如session 和cookie ,当然django对SESSION也提供了相关的方法