程序员

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

作者:admin 2021-08-04 我要评论

每xxxxx毫秒检测一次是否在线, TR_COUNT次之后设定改用户为假死状态(即不在当前页面活动,afk..) 当页面关闭时把停留时间送出, /**//*--------------------------...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)
每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);};
}

原文链接:https://m.jb51.net/article/14258.htm

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • 十月更新修复了Windows 10的Ping of De

    十月更新修复了Windows 10的Ping of De

  • Windows10 UAC弹窗太烦但又不能关?教

    Windows10 UAC弹窗太烦但又不能关?教

  • 老大手把手教我玩 Git 变基!

    老大手把手教我玩 Git 变基!

  • 在Linux终端中展示幻灯片

    在Linux终端中展示幻灯片