<script language=javascript>
var x = 0; var timer;
 function testtimeout(){timer = setTimeout("checktimeout()",3000); 
}
checktimeout=function(){
alert("已经超时!");
praent.window.location.replace("a.jsp");
}
function stoper() {
clearTimeout(timer);
}
</script><form name=xcv>
<input type=button onClick="testtimeout()" value=start>
<input type=button onClick="stoper()" value=stop>
</form>我在客户端设置一个计时器,当用户移动鼠标或键盘时,重设计时器,如果计时器触发,就跳回登陆网页或关闭窗口
现在问题是如何捕捉用户移动鼠标或键盘,在线等待大虾回答

解决方案 »

  1.   

    document.onkeydown
    document.onmousemove
      

  2.   

    你说的是
    checktimeout=function(){
     if(document.onkeydown||document.onmousemove){
    testtimeout();
    }else{
    alert("已经超时!");
    praent.window.location.replace("a.jsp");
    }
    }
    这样吗?
      

  3.   


    <html>
        <head>
        </head>
        <body>
    <form name=xcv>
    <input type=button onClick="testtimeout()" value=start>
    <input type=button onClick="stoper()" value=stop>
    </form>
      </body>
            <script type="text/javascript"> //这是你原来的写法,我给你改改哈~
    var x = 0; var timer;
    function testtimeout(){
    timer = setTimeout("checktimeout()",3000); 
    }
    checktimeout=function(){
    alert("已经超时!");
    parent.window.location.replace("a.jsp");
    }
    function stoper() {
    clearTimeout(timer);
    }
    //哦~你这是只写了好几个方法,但是不知道如何把他们绑到鼠标上是吧!//应该是一动就重新计时,
    //停止:
    //stoper();
    //重新计时:
     //testtimeout(); //封装起来 function letsgo(){
     stoper();
     testtimeout();
     } //绑到鼠标上去:
     document.onmousemove=letsgo;
     document.onkeydown=letsgo;
     //测试,搞定! 
     //整合一下: 
     /*
    var x = 0; var timer;
    function letsgo(){
    if(timer)clearTimeout(timer);
    timer = setTimeout(function(){
    alert("已经超时!");
    parent.window.location.replace("a.jsp");
    },3000); 
     }
     document.onmousemove=letsgo;
     document.onkeydown=letsgo;
    */        </script>
    </html>
      

  4.   

    参考:
    http://school.itzcn.com/special-spid-28.html
    上面讲解的比较详细,希望对楼主有所帮助。
      

  5.   

    document.onkeydown
    document.onmousemove
      

  6.   

    把话说清楚吗,方法都给你写好了~你才说你使用的框架嵌套,你使用了什么框架结构?最外层是
    frameset的组合?还是frame?iframe?