javascript(js)统计页面停留时间

<html> 
  <head> 
  <title>停留时间</title> 
  <meta http-equiv='content-type' content='text/html;charset=gbk'>
  <script   language="Javascript"> 
  <!--   Begin 
  pageOpen   =   new   Date(); 
  function   bye()   { 
  pageClose   =   new   Date(); 
  minutes   =   (pageClose.getMinutes()   -   pageOpen.getMinutes()); 
  seconds   =   (pageClose.getSeconds()   -   pageOpen.getSeconds()); 
  time   =   (seconds   +   (minutes   *   60)); 
  if   (time   ==   1)   { 
  time   =   (time   +   "   秒钟"); 
  } 
  else   { 
  time   =   (time   +   "   秒钟"); 
        } 
  alert('您在这儿呆了'   +   time   +   '.欢迎再来!'); 
  }   
  //   End   --> 
  </script> 
  </head> 
  <body   onunload="bye()" > 
  </body> 
  </html>  
 
<html> 
  <head> 
  <title>停留时间</title> 
  <meta http-equiv='content-type' content='text/html;charset=gbk'>
<script>

    var Temp;
    var TimerId = null;
    var TimerRunning = false;

    Seconds = 0
    Minutes = 0
    Hours = 0

    function showtime()
    {
      if(Seconds >= 59)
      {
        Seconds = 0
        if(Minutes >= 59)
        {
          Minutes = 0
          if(Hours >= 23)
          {
            Seconds = 0
            Minutes = 0
            Hours = 0
          }
          else {
            ++Hours
          }
        }
        else {
          ++Minutes
        }
      }
      else {
        ++Seconds
      }

      if(Seconds != 1) { var ss="s" } else { var ss="" }
      if(Minutes != 1) { var ms="s" } else { var ms="" }
      if(Hours != 1) { var hs="s" } else { var hs="" }

      Temp = '你在本页停留了 '+Hours+' 小时'+', '+Minutes+' 分'+', '+Seconds+' 秒'+''
      window.status = Temp;
      TimerId = setTimeout("showtime()", 1000);
      TimerRunning = true;
    }
    function waittime() {
      alert(Temp);
    }
    var TimerId = null;
    var TimerRunning = false;

    function stopClock() {
      if(TimerRunning)
        clearTimeout(TimerId);
        TimerRunning = false;
    }

    function startClock() {
      stopClock();
      showtime();
    }

    function stat(txt) {
      window.status = txt;
      setTimeout("erase()", 2000);
    }

    function erase() {
      window.status = "";
    }

</SCRIPT>


<!--第二步:把“onLoad="startClock()"”加在<body>标记里
例如:-->
<body onLoad="startClock()" onunload="waittime();">

<a href="http://www.bcbbs.net/Dev/HTML/jsrun/">欢迎访问编程联盟网页特效集</a>
300*300
 文章首页关于迷茫时代关于我写意人生
版权所有:迷茫时代 All rights reserved   
执行时间:0.00616 秒