欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

js统计网页在线时间的脚本

程序员文章站 2022-07-05 19:35:37
每xxxxx毫秒检测一次是否在线, tr_count次之后设定改用户为假死状态(即不在当前页面活动,afk..) 当页面关闭时把停留时间送出, /**//* --...
每xxxxx毫秒检测一次是否在线,
tr_count次之后设定改用户为假死状态(即不在当前页面活动,afk..)
当页面关闭时把停留时间送出,

/**//* ----------------------------------------------------------------------------
* script name: online.js
* last modified: 2008-4-13 22:25
* author: meyu
* copyright (c) 2008
* purpose: 跟踪在线时间
* ----------------------------------------------------------------------------*/

function tr_xmlhttpobject(url)...{
    this.xmlhttp=null;
    this.url=url;
    this.init=function()...{
        if(window.xmlhttprequest)...{
            this.xmlhttp=new xmlhttprequest();
        }else if(window.activexobject)...{
            this.xmlhttp=new activexobject("microsoft.xmlhttp");
        }
    };
    this.init();
    this.senddata=function(param)...{
        with(this.xmlhttp)...{
            open('get',this.url+(param||''),true);
            send(null);
        }
    };
}
if(/flag=flush/i.test(window.location.search))...{
    var tr_count=0;
    var tr_x=new tr_xmlhttpobject(window.location.href.replace(/&?(?:flush_count=)(d+)/i,
        function(a,d)...{
            tr_count=parseint(d);
            return "";
            })
    );
    function send()...{
        tr_count++;
        if(tr_count < 120)...{
            tr_x.senddata('&flush_count='+tr_count);
        }
    }
    window.setinterval(send,30000);
    window.onunload=function()...{tr_x.senddata('&flush_count='+tr_count);};
}