鼠标3秒不动,页面自动跳转到别的页面

index.html

Html代码 复制代码 收藏代码
  1.   
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">    
  3. <html xmlns="http://www.w3.org/1999/xhtml">    
  4. <head>    
  5. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />    
  6. <title>test跳转 </title>    
  7. <style type="text/css">    
  8. <!--   
  9. body{font-size:12px;color:#000000;}   
  10. -->    
  11. </style>    
  12. </head>    
  13.   
  14. <body>    
  15.   
  16.  <input name="aa" />  
  17. <iframe name="right" id="right" scrolling="no" src="aaaa.html" frameborder="0" width="740" height="500" style="z-index:1000; position:relative;"> </iframe>    
  18.   
  19. <script type="text/javascript">  
  20.    //指定多少毫秒无动作将跳转    
  21.      var timeout = 3000 ;     
  22.         
  23.      //记录当前时间    
  24.      var occurtime=new Date().getTime() ;    
  25.         
  26.     
  27.      //判断无动作时间并跳转    
  28.   function goUrl(){    
  29.     var a = parseInt(new Date().getTime() - occurtime);    
  30.     document.getElementById("aa").value=parseInt(a/1000);   
  31.     if(a>=timeout){    
  32.      window.location.href="http://www.g.cn";    
  33.     }    
  34. }    
  35. //隔1000毫秒判断一次   
  36. window.setInterval("goUrl()",1000);    
  37.   
  38. //如果鼠标在当前页面移动,则重新计时   
  39.  this.document.onmousemove=function(){   
  40.         alert("9999999");   
  41.             occurtime=new Date().getTime() ;   
  42.         }    
  43.   
  44.       
  45.           
  46.  </script>  
  47. </body>    
  48. </html>   
<!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>test跳转 </title> 
<style type="text/css"> 
<!-- 
body{font-size:12px;color:#000000;} 
--> 
</style> 
</head> 

<body> 

 <input name="aa" />
<iframe name="right" id="right" scrolling="no" src="aaaa.html" frameborder="0" width="740" height="500" style="z-index:1000; position:relative;"> </iframe> 

<script type="text/javascript">
   //指定多少毫秒无动作将跳转 
	 var timeout = 3000 ;  
	 
	 //记录当前时间 
	 var occurtime=new Date().getTime() ; 
	 
 
	 //判断无动作时间并跳转 
  function goUrl(){ 
	var a = parseInt(new Date().getTime() - occurtime); 
	document.getElementById("aa").value=parseInt(a/1000);
	if(a>=timeout){ 
	 window.location.href="http://www.g.cn"; 
	} 
} 
//隔1000毫秒判断一次
window.setInterval("goUrl()",1000); 

//如果鼠标在当前页面移动,则重新计时
 this.document.onmousemove=function(){
    	alert("9999999");
			occurtime=new Date().getTime() ;
    	} 

   
	   
 </script>
</body> 
</html> 




aaaa.html

Html代码 复制代码 收藏代码
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">    
  2. <html xmlns="http://www.w3.org/1999/xhtml">    
  3. <head>    
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />    
  5. <title>无标题文档 </title>    
  6. <style type="text/css">    
  7. <!--    
  8. body {    
  9. background-color: #CCCCCC;    
  10. }    
  11. -->    
  12. </style> </head>    
  13.   
  14. <body>    
  15. 三秒鼠标不动,则直接转向到http://www.g.cn   
  16. </body>    
  17. </html>   
posted @ 2011-11-22 11:10  java学弟  阅读(1040)  评论(0编辑  收藏  举报