///pc/img/blank.gif" width="12" height="8">当前位置:///default.htm" class="under">亿度网络 -> ///pc/index.htm" class="under">网页制作教程 -> JavaScript实例
///pc/homepage/javascript/sample/img/bule.gif" width="207" height="13"> ///pc/homepage/javascript/sample/img/blank.gif" width="1" height="1"> ///pc/homepage/javascript/sample/img/js.gif" width="186" height="20"> ///pc/homepage/javascript/sample/img/blank.gif" width="1" height="1">
///pc/homepage/javascript/sample/img/blank.gif" width="1" height="1"> ///pc/homepage/javascript/sample/img/blank.gif" width="1" height="1">
     离开时显示停留时间 ///pc/homepage/javascript/sample/img/blank.gif" width="1" height="1">  
  ///pc/homepage/javascript/sample/img/bule1.gif" width="28" height="49">  
 
源代码如下 ///pc/homepage/javascript/sample/img/bule2.gif" width="11" height="18">


这段程序放在<body>与</body>之间

这段程序放在<body ****>正文中

   
源程序讲解: ///pc/homepage/javascript/sample/img/bule2.gif" width="11" height="18">
  ///pc/homepage/javascript/sample/img/bule1.gif" width="28" height="49">  

pageOpen = new Date();
定义一个新的日期对象,纪录开始浏览页面时间。
function stay() 定义一个函数。
pageClose = new Date();
定义一个新的日期对象,纪录结束浏览页面时间。
minutes = (pageClose.getMinutes() - pageOpen.getMinutes());
“分钟”变量等于结束时间的分钟数减去开始时间的分钟数。
seconds = (pageClose.getSeconds() - pageOpen.getSeconds());
“秒数”变量等于结束时间的秒数数减去开始时间的秒数数。
time = (seconds + (minutes * 60));
时间变量等于“秒数”变量加上“分钟”变量乘以60,即变为以秒纪录。
time = (time + " 秒钟"); alert('您在这儿停留了' + time + '.欢迎下次再来!');
alert()是JavaScript的窗口对象方法,其功能是弹出一个具有OK对话框并显示()中的字符串 ,告诉在此页面停留的时间。
onUnload=stay() 页面卸载的时候,调用stay()函数。

  ///pc/homepage/javascript/sample/img/blank.gif" width="1" height="1">  
 

 

网页制作 网页设计 网站建设 网站设计 网站制作 做网站 做网页